Skip to content

Commit

Permalink
Add name attribute to Vedeu::Views::Char;
Browse files Browse the repository at this point in the history
This allows us to then fetch the respective interface for the Char, which should
make colour/style fetching faster.

Work relating to #302.
  • Loading branch information
gavinlaking committed Nov 12, 2015
1 parent 2af6de8 commit c6ecacc
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/vedeu/models/views/char.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ class Char
# @return [NilClass|Symbol]
attr_accessor :border

# @!attribute [rw] name
# @return [String|Symbol]
attr_accessor :name

# @!attribute [rw] parent
# @return [Vedeu::Views::Line]
attr_accessor :parent
Expand All @@ -45,6 +49,7 @@ class Char
# A symbol representing the border 'piece' this
# {Vedeu::Views::Char} represents.
# @option attributes colour [Vedeu::Colours::Colour]
# @option attributes name [String|Symbol]
# @option attributes parent [Vedeu::Views::Line]
# @option attributes position [Vedeu::Geometry::Position]
# @option attributes style [Vedeu::Presentation::Style]
Expand All @@ -53,6 +58,7 @@ class Char
def initialize(attributes = {})
@attributes = attributes
@border = @attributes[:border]
@name = @attributes[:name]
@parent = @attributes[:parent]
@value = @attributes[:value]
end
Expand Down Expand Up @@ -83,6 +89,11 @@ def eql?(other)
end
alias_method :==, :eql?

# @return [Vedeu::Interfaces::Interface]
def interface
@interface ||= Vedeu.interfaces.by_name(name)
end

# @return [Vedeu::Geometry::Position]
def position
@position = Vedeu::Geometry::Position.coerce(@attributes[:position])
Expand Down Expand Up @@ -130,6 +141,7 @@ def to_hash
{
border: border.to_s,
colour: colour_to_hash,
name: name.to_s,
parent: parent_to_hash,
position: position_to_hash,
style: style.to_s,
Expand Down
18 changes: 18 additions & 0 deletions test/lib/vedeu/models/views/char_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ module Views
{
border: border,
colour: colour,
name: _name,
parent: parent,
position: position,
style: style,
Expand All @@ -43,6 +44,7 @@ module Views
}
let(:border) { nil }
let(:colour) { nil }
let(:_name) { nil }
let(:style) { nil }
let(:position) { nil }
let(:parent_colour) { nil }
Expand All @@ -51,6 +53,7 @@ module Views
describe '#initialize' do
it { instance.must_be_instance_of(described) }
it { instance.instance_variable_get('@border').must_equal(border) }
it { instance.instance_variable_get('@name').must_equal(_name) }
it { instance.instance_variable_get('@parent').must_equal(parent) }
it { instance.instance_variable_get('@value').must_equal(_value) }

Expand All @@ -61,6 +64,8 @@ module Views
it {
instance.must_respond_to(:border)
instance.must_respond_to(:border=)
instance.must_respond_to(:name)
instance.must_respond_to(:name=)
instance.must_respond_to(:parent)
instance.must_respond_to(:parent=)
instance.must_respond_to(:attributes)
Expand Down Expand Up @@ -92,6 +97,18 @@ module Views
end
end

describe '#interface' do
let(:interface) { Vedeu::Interfaces::Interface.new }

before do
Vedeu.interfaces.stubs(:by_name).with(_name).returns(interface)
end

subject { instance.interface }

it { subject.must_be_instance_of(Vedeu::Interfaces::Interface) }
end

describe '#position' do
subject { instance.position }
end
Expand All @@ -111,6 +128,7 @@ module Views
background: '',
foreground: '',
},
name: '',
parent: {
background: '',
foreground: '',
Expand Down
1 change: 1 addition & 0 deletions test/lib/vedeu/output/renderers/json_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ module Renderers
" \"background\": \"\\u001b[48;2;255;0;0m\",\n" \
" \"foreground\": \"\\u001b[38;2;255;255;255m\"\n" \
" },\n" \
" \"name\": \"\",\n" \
" \"parent\": {\n" \
" },\n" \
" \"position\": {\n" \
Expand Down

0 comments on commit c6ecacc

Please sign in to comment.