Skip to content

Commit

Permalink
Delegate some methods, also;
Browse files Browse the repository at this point in the history
Add more tests.
  • Loading branch information
gavinlaking committed May 21, 2016
1 parent 553fb54 commit dbddbbb
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 78 deletions.
42 changes: 11 additions & 31 deletions lib/vedeu/interfaces/clear.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@ module Interfaces
class Clear

include Vedeu::Common
extend Forwardable

def_delegators :geometry,
:height,
:width,
:x,
:y

def_delegators :interface,
:colour

class << self

Expand Down Expand Up @@ -48,29 +58,14 @@ def render

private

# @return [String] A string of blank characters.
def chars
@_chars ||= (' ' * width)
end

# @return [Vedeu::Colours::Colour]
def colour
@_colour ||= interface.colour
end

# @macro geometry_by_name
def geometry
@_geometry ||= Vedeu.geometries.by_name(name)
end

# @return [Fixnum]
def height
@_height ||= geometry.height
end

# @macro interface_by_name
def interface
Vedeu.interfaces.by_name(name)
@_interface ||= Vedeu.interfaces.by_name(name)
end

# For each visible line of the interface, set the foreground and
Expand Down Expand Up @@ -100,21 +95,6 @@ def output_attributes(iy, ix)
}
end

# @return [Fixnum]
def width
@_width ||= geometry.width
end

# @return [Fixnum]
def y
@_y ||= geometry.y
end

# @return [Fixnum]
def x
@_x ||= geometry.x
end

end # Clear

end # Interfaces
Expand Down
53 changes: 19 additions & 34 deletions lib/vedeu/interfaces/clear_content.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@ module Interfaces
class ClearContent

include Vedeu::Common
extend Forwardable

def_delegators :geometry,
:bordered_height,
:bordered_width,
:bx,
:by

def_delegators :interface,
:colour

class << self

Expand Down Expand Up @@ -50,39 +60,29 @@ def render

# @return [String] A string of blank characters.
def chars
@_chars ||= (' ' * width)
end

# @return [Vedeu::Colours::Colour]
def colour
@_colour ||= interface.colour
@_chars ||= (' ' * bordered_width)
end

# @macro geometry_by_name
def geometry
@_geometry ||= Vedeu.geometries.by_name(name)
end

# @return [Fixnum]
def height
@_height ||= geometry.bordered_height
end

# @macro interface_by_name
def interface
Vedeu.interfaces.by_name(name)
@_interface ||= Vedeu.interfaces.by_name(name)
end

# @return [String]
def optimised_output
Vedeu.timer("Optimised clearing content: '#{name}'") do
Array.new(height) do |iy|
Array.new(bordered_height) do |iy|
[
Vedeu::Geometries::Position.new(y + iy, x).to_s,
Vedeu::Geometries::Position.new(by + iy, bx),
colour.to_s,
chars,
].join
end.join + Vedeu::Geometries::Position.new(y, x).to_s
end.join + Vedeu::Geometries::Position.new(by, bx)
end
end

Expand All @@ -94,32 +94,17 @@ def optimised_output
# @return [Array<Array<Vedeu::Cells::Char>>]
def output
Vedeu.timer("Clearing content: '#{name}'") do
@_clear ||= Array.new(height) do |iy|
Array.new(width) do |ix|
position = Vedeu::Geometries::Position.new((y + iy), (x + ix))
@_clear ||= Array.new(bordered_height) do |iy|
Array.new(bordered_width) do |ix|
Vedeu::Cells::Clear.new(colour: colour,
name: name,
position: position)
position: Vedeu::Geometries::Position
.new((by + iy), (bx + ix)))
end
end
end
end

# @return [Fixnum]
def width
@_width ||= geometry.bordered_width
end

# @return [Fixnum]
def y
@_y ||= geometry.by
end

# @return [Fixnum]
def x
@_x ||= geometry.bx
end

end # ClearContent

end # Interfaces
Expand Down
27 changes: 19 additions & 8 deletions test/lib/vedeu/interfaces/clear_content_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,20 +60,31 @@ module Interfaces
Vedeu.geometries.stubs(:by_name).returns(geometry)
Vedeu.stubs(:direct_write)
Vedeu.stubs(:buffer_update)
Vedeu.stubs(:ready?).returns(ready)
end

subject { instance.render }

# it { subject.must_be_instance_of(Vedeu::Buffers::View) }
it do
Vedeu.expects(:direct_write)
subject
context 'when Vedeu is ready' do
let(:ready) { true }

# it { subject.must_be_instance_of(Vedeu::Buffers::View) }
it do
Vedeu.expects(:direct_write)
subject
end
it do
Vedeu.expects(:buffer_update)
subject
end
# it { subject.must_equal(output) }
end
it do
Vedeu.expects(:buffer_update)
subject

context 'when Vedeu is not ready' do
let(:ready) { false }

it { subject.must_be_instance_of(NilClass) }
end
# it { subject.must_equal(output) }
end

end # ClearContent
Expand Down
23 changes: 18 additions & 5 deletions test/lib/vedeu/interfaces/clear_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,29 @@ module Interfaces
Vedeu.interfaces.stubs(:by_name).returns(interface)
Vedeu.geometries.stubs(:by_name).returns(geometry)
Vedeu.stubs(:render_output).returns(output)
Vedeu.stubs(:ready?).returns(ready)
end

subject { instance.render }

it { subject.must_be_instance_of(Array) }
it do
Vedeu.expects(:render_output).with(output)
subject
context 'when Vedeu is ready' do
let(:ready) { true }

it { subject.must_be_instance_of(Array) }

it do
Vedeu.expects(:render_output).with(output)
subject
end

it { subject.must_equal(output) }
end

context 'when Vedeu is not ready' do
let(:ready) { false }

it { subject.must_be_instance_of(NilClass) }
end
it { subject.must_equal(output) }
end

end # Clear
Expand Down

0 comments on commit dbddbbb

Please sign in to comment.