vedeu 0.6.70 → 0.6.71

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/lib/vedeu/borders/caption.rb +2 -2
  3. data/lib/vedeu/borders/refresh.rb +3 -4
  4. data/lib/vedeu/borders/set_attribute.rb +4 -0
  5. data/lib/vedeu/borders/title.rb +11 -11
  6. data/lib/vedeu/cursors/cursor.rb +1 -1
  7. data/lib/vedeu/cursors/move.rb +3 -0
  8. data/lib/vedeu/dsl/lines.rb +2 -0
  9. data/lib/vedeu/dsl/streams.rb +2 -0
  10. data/lib/vedeu/editor/cursor.rb +1 -0
  11. data/lib/vedeu/editor/lines.rb +1 -0
  12. data/lib/vedeu/esc/esc.rb +1 -1
  13. data/lib/vedeu/geometries/all.rb +1 -0
  14. data/lib/vedeu/geometries/position.rb +14 -5
  15. data/lib/vedeu/geometries/positionable.rb +55 -0
  16. data/lib/vedeu/interfaces/clear.rb +6 -3
  17. data/lib/vedeu/models/cell.rb +2 -5
  18. data/lib/vedeu/models/escape.rb +2 -5
  19. data/lib/vedeu/output/write.rb +1 -0
  20. data/lib/vedeu/presentation/background.rb +5 -0
  21. data/lib/vedeu/presentation/foreground.rb +5 -0
  22. data/lib/vedeu/presentation/presentation.rb +5 -10
  23. data/lib/vedeu/version.rb +1 -1
  24. data/lib/vedeu/views/char.rb +4 -36
  25. data/test/lib/vedeu/borders/caption_test.rb +39 -7
  26. data/test/lib/vedeu/borders/title_test.rb +44 -17
  27. data/test/lib/vedeu/editor/cursor_test.rb +2 -0
  28. data/test/lib/vedeu/editor/lines_test.rb +2 -0
  29. data/test/lib/vedeu/geometries/position_test.rb +84 -24
  30. data/test/lib/vedeu/geometries/positionable_test.rb +67 -0
  31. data/test/lib/vedeu/models/cell_test.rb +1 -0
  32. data/test/lib/vedeu/models/escape_test.rb +0 -10
  33. data/test/lib/vedeu/renderers/json_test.rb +0 -4
  34. data/test/lib/vedeu/views/char_test.rb +25 -60
  35. data/vedeu.gemspec +1 -1
  36. metadata +6 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6a215a258800fb64a1c3493c3a504bfed883fc54
4
- data.tar.gz: f6b96d7ba7a7e0b5aca5e55ef211a3afc5b50f4c
3
+ metadata.gz: e6f85cb55a50d53c490a1a1f8f0bb3adbf38035d
4
+ data.tar.gz: 98154c75cbe858bb6ec6810f8a9887ebca55ffbb
5
5
  SHA512:
6
- metadata.gz: 901c2cce80b9ec3468c80c538e8c6b8b372cea78db1fae7b04cfee13bf0b457ade911966d1086b0bec8b4f04d9270ec08d0a7b9e1296aac56011fbd1e56d5b69
7
- data.tar.gz: b747cefb06613a45addde327f5183c13cfa8d7dc0cfcf2367b6b75ebf65bd581d4f595f2bbd329ebc47739a8fe86d8e2befd9111c0e74d7af4b4d3a25ae4e8fa
6
+ metadata.gz: 23e2508ccb6cac4af70ef49caa6cd8be4c13cb71233f3b121a78979fbda7956a4e0efa79c7b518558bb3054d11a6cb9c69b6bfe263afa4bdd1a9ed9941b9e5ce
7
+ data.tar.gz: ee5c80b253f55995582811f1f579ce8c2a408be5adb5ec699d1ddd87ae36f3a13dce1c4a4616a3831a1336758b0cf69555b8274fde96a2ca5d4ab6f0e36d4a3b
@@ -20,7 +20,7 @@ module Vedeu
20
20
 
21
21
  caption_index = 0
22
22
  chars.each_with_index do |char, index|
23
- next if index <= start_index || index > (width - 4)
23
+ next if index <= start_index || index > (width - 2)
24
24
 
25
25
  char.border = nil
26
26
  char.value = characters[caption_index]
@@ -32,7 +32,7 @@ module Vedeu
32
32
 
33
33
  # @return [Fixnum]
34
34
  def start_index
35
- (width - size) - 4
35
+ (width - size) - 2
36
36
  end
37
37
 
38
38
  end # Caption
@@ -130,7 +130,7 @@ module Vedeu
130
130
  #
131
131
  # @return [Array<Vedeu::Views::Char>]
132
132
  def build_top
133
- build_horizontal(:bottom_horizontal, y)
133
+ build_horizontal(:top_horizontal, y)
134
134
  end
135
135
 
136
136
  # Creates a bottom border character.
@@ -237,8 +237,7 @@ module Vedeu
237
237
  def captionbar
238
238
  return nil unless caption
239
239
 
240
- @_caption ||= Vedeu::Borders::Caption
241
- .render(caption, width, build_bottom)
240
+ @_caption ||= Vedeu::Borders::Caption.render(caption, build_bottom)
242
241
  end
243
242
 
244
243
  # An optional title for when the top border is to be shown.
@@ -248,7 +247,7 @@ module Vedeu
248
247
  def titlebar
249
248
  return nil unless title
250
249
 
251
- @_title ||= Vedeu::Borders::Title.render(title, width, build_top)
250
+ @_title ||= Vedeu::Borders::Title.render(title, build_top)
252
251
  end
253
252
 
254
253
  end # Refresh
@@ -2,6 +2,10 @@ module Vedeu
2
2
 
3
3
  module Borders
4
4
 
5
+ # Provides the mechanism to set attributes on a
6
+ # {Vedeu::Borders::Border} object. At the moment, it is used for
7
+ # setting the title and caption for a named border.
8
+ #
5
9
  # @api private
6
10
  #
7
11
  class SetAttribute
@@ -10,12 +10,12 @@ module Vedeu
10
10
  #
11
11
  class Title
12
12
 
13
+ # @param chars [Array<Vedeu::Views::Char>]
13
14
  # @param value [String|Vedeu::Borders::Title|
14
15
  # Vedeu::Borders::Caption]
15
- # @param width [Fixnum]
16
- # @return [Vedeu::Borders::Title|Vedeu::Borders::Caption]
17
- def self.render(value = '', width = Vedeu.width, chars = [])
18
- new(value, width, chars).render
16
+ # @return [Array<Vedeu::Views::Char>]
17
+ def self.render(value = '', chars = [])
18
+ new(value, chars).render
19
19
  end
20
20
 
21
21
  # Returns a new instance of Vedeu::Borders::Title or
@@ -24,11 +24,9 @@ module Vedeu
24
24
  # @param chars [Array<Vedeu::Views::Char>]
25
25
  # @param value [String|Vedeu::Borders::Title|
26
26
  # Vedeu::Borders::Caption]
27
- # @param width [Fixnum]
28
27
  # @return [Vedeu::Borders::Title|Vedeu::Borders::Caption]
29
- def initialize(value = '', width = Vedeu.width, chars = [])
28
+ def initialize(value = '', chars = [])
30
29
  @value = value
31
- @width = width
32
30
  @chars = chars
33
31
  end
34
32
 
@@ -63,8 +61,9 @@ module Vedeu
63
61
  def to_s
64
62
  value.to_s
65
63
  end
64
+ alias_method :to_str, :to_s
66
65
 
67
- # Return the value or an empty string.
66
+ # Return the value (a title or a caption) or an empty string.
68
67
  #
69
68
  # @return [String]
70
69
  def value
@@ -76,7 +75,8 @@ module Vedeu
76
75
  protected
77
76
 
78
77
  # @!attribute [r] chars
79
- # @return [Array<Vedeu::Views::Char>]
78
+ # @return [Array<Vedeu::Views::Char>] An array of border
79
+ # characters.
80
80
  attr_reader :chars
81
81
 
82
82
  private
@@ -141,11 +141,11 @@ module Vedeu
141
141
  title.chomp.slice(0...(width - 4))
142
142
  end
143
143
 
144
- # Return the given width or the width of the terminal.
144
+ # Return the size of the horizontal border given via #chars.
145
145
  #
146
146
  # @return [Fixnum]
147
147
  def width
148
- @width || Vedeu.width
148
+ chars.size
149
149
  end
150
150
 
151
151
  end # Title
@@ -216,7 +216,7 @@ module Vedeu
216
216
  #
217
217
  # @return [Vedeu::Geometries::Position]
218
218
  def position
219
- @position = Vedeu::Geometries::Position[y, x]
219
+ @position = Vedeu::Geometries::Position.coerce([y, x])
220
220
  end
221
221
 
222
222
  # Show a named cursor, or without a name, the cursor of the
@@ -2,6 +2,9 @@ module Vedeu
2
2
 
3
3
  module Cursors
4
4
 
5
+ # Provides the mechanism to move a named cursor in a given
6
+ # direction.
7
+ #
5
8
  # @api private
6
9
  #
7
10
  class Move
@@ -2,6 +2,8 @@ module Vedeu
2
2
 
3
3
  module DSL
4
4
 
5
+ # Provides the mechanism to add lines to a view via the DSL.
6
+ #
5
7
  class Lines
6
8
 
7
9
  # @raise [Vedeu::Error::RequiresBlock]
@@ -2,6 +2,8 @@ module Vedeu
2
2
 
3
3
  module DSL
4
4
 
5
+ # Provides the mechanism to add streams to a line via the DSL.
6
+ #
5
7
  class Streams
6
8
 
7
9
  # @raise [Vedeu::Error::RequiresBlock]
@@ -131,6 +131,7 @@ module Vedeu
131
131
  def to_s
132
132
  "\e[#{real_y};#{real_x}H\e[?25h".freeze
133
133
  end
134
+ alias_method :to_str, :to_s
134
135
 
135
136
  # Move the virtual cursor up by one line.
136
137
  #
@@ -120,6 +120,7 @@ module Vedeu
120
120
  def to_s
121
121
  collection.map(&:to_s).join
122
122
  end
123
+ alias_method :to_str, :to_s
123
124
 
124
125
  end # Lines
125
126
 
data/lib/vedeu/esc/esc.rb CHANGED
@@ -115,7 +115,7 @@ module Vedeu
115
115
 
116
116
  # @return [String]
117
117
  def last_character_position
118
- Vedeu::Geometries::Position[Vedeu.height, Vedeu.width].to_s
118
+ Vedeu::Geometries::Position.coerce([Vedeu.height, Vedeu.width]).to_s
119
119
  end
120
120
 
121
121
  end # Esc
@@ -20,4 +20,5 @@ require 'vedeu/geometries/dsl/all'
20
20
  require 'vedeu/geometries/geometry'
21
21
  require 'vedeu/geometries/move'
22
22
  require 'vedeu/geometries/position'
23
+ require 'vedeu/geometries/positionable'
23
24
  require 'vedeu/geometries/repository'
@@ -22,11 +22,12 @@ module Vedeu
22
22
  # Convenience constructor for Vedeu::Geometries::Position.
23
23
  #
24
24
  # @param (see #initialize)
25
- def self.[](y, x)
25
+ def self.[](y = 1, x = 1)
26
26
  new(y, x)
27
27
  end
28
28
 
29
- # @param value [Array<Fixnum>|Vedeu::Geometries::Position]
29
+ # @param value [Array<Fixnum>|Fixnum|Hash|
30
+ # Vedeu::Geometries::Position]
30
31
  # @return [Vedeu::Geometries::Position]
31
32
  def self.coerce(value)
32
33
  if value.is_a?(self)
@@ -35,6 +36,9 @@ module Vedeu
35
36
  elsif value.is_a?(Array)
36
37
  new(*value)
37
38
 
39
+ elsif value.is_a?(Fixnum)
40
+ new(value, 1)
41
+
38
42
  elsif value.is_a?(Hash)
39
43
  new(value.fetch(:y, 1), value.fetch(:x, 1))
40
44
 
@@ -92,9 +96,14 @@ module Vedeu
92
96
  [y, x]
93
97
  end
94
98
 
95
- # @return [Vedeu::Geometries::Position]
96
- def to_position
97
- self
99
+ # Return the position as a Hash.
100
+ #
101
+ # @return [Hash<Symbol => Fixnum|NilClass>]
102
+ def to_h
103
+ {
104
+ y: y,
105
+ x: x,
106
+ }
98
107
  end
99
108
 
100
109
  # Return the escape sequence required to position the cursor at
@@ -0,0 +1,55 @@
1
+ module Vedeu
2
+
3
+ module Geometries
4
+
5
+ # Provide position functionality to the including model.
6
+ #
7
+ # @api private
8
+ #
9
+ module Positionable
10
+
11
+ # Gets the position.
12
+ #
13
+ # @return [Vedeu::Geometries::Position]
14
+ def position
15
+ @_position ||= Vedeu::Geometries::Position.coerce(@position)
16
+ end
17
+
18
+ # Sets the position.
19
+ #
20
+ # @param value [Array<void>|Hash<void>|
21
+ # Vedeu::Geometries::Position]
22
+ # @return [Vedeu::Geometries::Position]
23
+ def position=(value)
24
+ @_position = @position = Vedeu::Geometries::Position.coerce(value)
25
+ end
26
+
27
+ # Returns a boolean indicating the position attribute of the
28
+ # including model is set.
29
+ #
30
+ # @return [Boolean]
31
+ def position?
32
+ position.is_a?(Vedeu::Geometries::Position)
33
+ end
34
+
35
+ # Returns the x coordinate for the model when the position
36
+ # attribute of the including model is set.
37
+ #
38
+ # @return [Fixnum|NilClass]
39
+ def x
40
+ position.x if position?
41
+ end
42
+
43
+ # Returns the y coordinate for the model when the position
44
+ # attribute of the including model is set.
45
+ #
46
+ # @return [Fixnum|NilClass]
47
+ def y
48
+ position.y if position?
49
+ end
50
+
51
+ end # Positionable
52
+
53
+ end # Geometries
54
+
55
+ end # Vedeu
@@ -142,11 +142,11 @@ module Vedeu
142
142
  Vedeu.timer("Optimised clearing #{clearing}: '#{name}'".freeze) do
143
143
  height.times.map do |iy|
144
144
  [
145
- position(y + iy, x),
145
+ build_position(y + iy, x),
146
146
  colour.to_s,
147
147
  chars,
148
148
  ].join
149
- end.join + position(y, x)
149
+ end.join + build_position(y, x)
150
150
  end
151
151
  end
152
152
 
@@ -180,8 +180,11 @@ module Vedeu
180
180
  end
181
181
  end
182
182
 
183
+ # @param pos_y [Fixnum]
184
+ # @param pos_x [Fixnum]
183
185
  # @return [Vedeu::Geometries::Position]
184
- def position(pos_y, pos_x)
186
+ # @todo Not sure if #to_s is required here. (GL: 2015-11-30)
187
+ def build_position(pos_y, pos_x)
185
188
  Vedeu::Geometries::Position.new(pos_y, pos_x).to_s
186
189
  end
187
190
 
@@ -9,6 +9,7 @@ module Vedeu
9
9
  class Cell
10
10
 
11
11
  include Vedeu::Repositories::Defaults
12
+ include Vedeu::Geometries::Positionable
12
13
 
13
14
  # @!attribute [r] colour
14
15
  # @return [NilClass|String]
@@ -46,11 +47,6 @@ module Vedeu
46
47
  @interface ||= Vedeu.interfaces.by_name(name)
47
48
  end
48
49
 
49
- # @return [Vedeu::Geometries::Position]
50
- def position
51
- Vedeu::Geometries::Position.coerce(@position)
52
- end
53
-
54
50
  # @return [Hash]
55
51
  def to_hash
56
52
  {
@@ -71,6 +67,7 @@ module Vedeu
71
67
  def to_s
72
68
  value.to_s
73
69
  end
70
+ alias_method :to_str, :to_s
74
71
 
75
72
  private
76
73
 
@@ -8,6 +8,8 @@ module Vedeu
8
8
  #
9
9
  class Escape
10
10
 
11
+ include Vedeu::Geometries::Positionable
12
+
11
13
  # @!attribute [r] value
12
14
  # @return [String]
13
15
  attr_reader :value
@@ -48,11 +50,6 @@ module Vedeu
48
50
  end
49
51
  alias_method :==, :eql?
50
52
 
51
- # @return [String]
52
- def position
53
- Vedeu::Geometries::Position.coerce(@position)
54
- end
55
-
56
53
  # Return an empty hash as most escape sequences won't make
57
54
  # sense as JSON.
58
55
  #
@@ -103,6 +103,7 @@ module Vedeu
103
103
  Vedeu::EscapeSequences::Esc.reset +
104
104
  position(position_end)
105
105
  end
106
+ alias_method :to_str, :to_s
106
107
 
107
108
  end # Write
108
109
 
@@ -4,6 +4,11 @@ module Vedeu
4
4
 
5
5
  module Colour
6
6
 
7
+ # Provides the background colour when included in a class with
8
+ # a colour attribute.
9
+ #
10
+ # @api private
11
+ #
7
12
  module Background
8
13
 
9
14
  include Vedeu::Repositories::Parent
@@ -4,6 +4,11 @@ module Vedeu
4
4
 
5
5
  module Colour
6
6
 
7
+ # Provides the foreground colour when included in a class with
8
+ # a colour attribute.
9
+ #
10
+ # @api private
11
+ #
7
12
  module Foreground
8
13
 
9
14
  include Vedeu::Repositories::Parent
@@ -1,7 +1,10 @@
1
+ require 'vedeu/geometries/positionable'
2
+
1
3
  module Vedeu
2
4
 
3
5
  module Presentation
4
6
 
7
+ include Vedeu::Geometries::Positionable
5
8
  include Vedeu::Presentation::Colour
6
9
  include Vedeu::Presentation::Styles
7
10
 
@@ -17,14 +20,6 @@ module Vedeu
17
20
 
18
21
  private
19
22
 
20
- # Returns a boolean indicating the model has a position
21
- # attribute.
22
- #
23
- # @return [Boolean]
24
- def position?
25
- self.respond_to?(:position) && position.is_a?(Vedeu::Geometries::Position)
26
- end
27
-
28
23
  # Renders the colour attributes of the receiver and yields (to
29
24
  # then render the styles).
30
25
  #
@@ -35,9 +30,9 @@ module Vedeu
35
30
 
36
31
  # @return [String]
37
32
  def render_position
38
- return yield unless position?
33
+ return position.to_s { yield } if position?
39
34
 
40
- position.to_s { yield }
35
+ yield
41
36
  end
42
37
 
43
38
  # Renders the style attributes of the receiver and yields (to
data/lib/vedeu/version.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  module Vedeu
2
2
 
3
3
  # The current version of Vedeu.
4
- VERSION = '0.6.70'.freeze
4
+ VERSION = '0.6.71'.freeze
5
5
 
6
6
  end
@@ -1,3 +1,5 @@
1
+ require 'vedeu/geometries/positionable'
2
+
1
3
  module Vedeu
2
4
 
3
5
  module Views
@@ -12,6 +14,7 @@ module Vedeu
12
14
  class Char
13
15
 
14
16
  include Comparable
17
+ include Vedeu::Geometries::Positionable
15
18
  include Vedeu::Repositories::Parent
16
19
  include Vedeu::Presentation
17
20
 
@@ -94,19 +97,6 @@ module Vedeu
94
97
  @interface ||= Vedeu.interfaces.by_name(name)
95
98
  end
96
99
 
97
- # @return [Vedeu::Geometries::Position]
98
- def position
99
- @_position ||= Vedeu::Geometries::Position.coerce(@position)
100
- end
101
-
102
- # Sets the position of the Vedeu::Views::Char.
103
- #
104
- # @param value [Array<void>|Hash<void>|Vedeu::Geometries::Position]
105
- # @return [Vedeu::Geometries::Position]
106
- def position=(value)
107
- @_position = @position = Vedeu::Geometries::Position.coerce(value)
108
- end
109
-
110
100
  # @return [String]
111
101
  def value
112
102
  return @value unless border
@@ -114,20 +104,6 @@ module Vedeu
114
104
  Vedeu::EscapeSequences::Esc.border { @value }
115
105
  end
116
106
 
117
- # Returns the x position for the Vedeu::Views::Char when set.
118
- #
119
- # @return [Fixnum|NilClass]
120
- def x
121
- position.x if position
122
- end
123
-
124
- # Returns the y position for the Vedeu::Views::Char when set.
125
- #
126
- # @return [Fixnum|NilClass]
127
- def y
128
- position.y if position
129
- end
130
-
131
107
  # Returns a Hash of all the values before coercion.
132
108
  #
133
109
  # @note
@@ -142,7 +118,7 @@ module Vedeu
142
118
  colour: colour_to_hash,
143
119
  name: name.to_s,
144
120
  parent: parent_to_hash,
145
- position: position_to_hash,
121
+ position: position.to_h,
146
122
  style: style.to_s,
147
123
  value: value,
148
124
  }
@@ -189,14 +165,6 @@ module Vedeu
189
165
  }
190
166
  end
191
167
 
192
- # @return [Hash<Symbol => Fixnum>]
193
- def position_to_hash
194
- {
195
- y: y,
196
- x: x,
197
- }
198
- end
199
-
200
168
  end # Char
201
169
 
202
170
  end # Views
@@ -6,19 +6,51 @@ module Vedeu
6
6
 
7
7
  describe Caption do
8
8
 
9
- let(:instance) {}
9
+ let(:described) { Vedeu::Borders::Caption }
10
+ let(:instance) { described.new(_value, chars) }
11
+ let(:_value) { 'Bismuth' }
12
+ let(:chars) {
13
+ [
14
+ Vedeu::Views::Char.new(value: '-', position: [4, 1], border: type),
15
+ Vedeu::Views::Char.new(value: '-', position: [4, 2], border: type),
16
+ Vedeu::Views::Char.new(value: '-', position: [4, 3], border: type),
17
+ Vedeu::Views::Char.new(value: '-', position: [4, 4], border: type),
18
+ Vedeu::Views::Char.new(value: '-', position: [4, 5], border: type),
19
+ Vedeu::Views::Char.new(value: '-', position: [4, 6], border: type),
20
+ Vedeu::Views::Char.new(value: '-', position: [4, 7], border: type),
21
+ Vedeu::Views::Char.new(value: '-', position: [4, 8], border: type),
22
+ Vedeu::Views::Char.new(value: '-', position: [4, 9], border: type),
23
+ Vedeu::Views::Char.new(value: '-', position: [4, 10], border: type),
24
+ ]
25
+ }
26
+ let(:type) { :bottom_horizontal }
10
27
 
11
28
  describe '#render' do
12
- let(:top_border) {}
29
+ subject { instance.render }
13
30
 
14
- subject { instance.render(top_border) }
31
+ context 'when the caption is empty' do
32
+ let(:_value) {}
15
33
 
16
- context 'when the title is empty' do
17
- # @todo Add more tests.
34
+ it { subject.must_equal(chars) }
18
35
  end
19
36
 
20
- context 'when the title is not empty' do
21
- # @todo Add more tests.
37
+ context 'when the caption is not empty' do
38
+ let(:expected) {
39
+ [
40
+ Vedeu::Views::Char.new(value: '-', position: [4, 1], border: type),
41
+ Vedeu::Views::Char.new(value: ' ', position: [4, 2], border: nil),
42
+ Vedeu::Views::Char.new(value: 'B', position: [4, 3], border: nil),
43
+ Vedeu::Views::Char.new(value: 'i', position: [4, 4], border: nil),
44
+ Vedeu::Views::Char.new(value: 's', position: [4, 5], border: nil),
45
+ Vedeu::Views::Char.new(value: 'm', position: [4, 6], border: nil),
46
+ Vedeu::Views::Char.new(value: 'u', position: [4, 7], border: nil),
47
+ Vedeu::Views::Char.new(value: 't', position: [4, 8], border: nil),
48
+ Vedeu::Views::Char.new(value: ' ', position: [4, 9], border: nil),
49
+ Vedeu::Views::Char.new(value: '-', position: [4, 10], border: type),
50
+ ]
51
+ }
52
+
53
+ it { subject.must_equal(expected) }
22
54
  end
23
55
  end
24
56
 
@@ -7,22 +7,57 @@ module Vedeu
7
7
  describe Title do
8
8
 
9
9
  let(:described) { Vedeu::Borders::Title }
10
- let(:instance) { described.new(_value, width, chars) }
10
+ let(:instance) { described.new(_value, chars) }
11
11
  let(:_value) { 'Aluminium' }
12
- let(:width) { 10 }
13
- let(:chars) { [] }
12
+ let(:chars) {
13
+ [
14
+ Vedeu::Views::Char.new(value: '-', position: [1, 1], border: type),
15
+ Vedeu::Views::Char.new(value: '-', position: [1, 2], border: type),
16
+ Vedeu::Views::Char.new(value: '-', position: [1, 3], border: type),
17
+ Vedeu::Views::Char.new(value: '-', position: [1, 4], border: type),
18
+ Vedeu::Views::Char.new(value: '-', position: [1, 5], border: type),
19
+ Vedeu::Views::Char.new(value: '-', position: [1, 6], border: type),
20
+ Vedeu::Views::Char.new(value: '-', position: [1, 7], border: type),
21
+ Vedeu::Views::Char.new(value: '-', position: [1, 8], border: type),
22
+ Vedeu::Views::Char.new(value: '-', position: [1, 9], border: type),
23
+ Vedeu::Views::Char.new(value: '-', position: [1, 10], border: type),
24
+ ]
25
+ }
26
+ let(:type) { :top_horizontal }
14
27
 
15
28
  describe '#initialize' do
16
29
  it { instance.must_be_instance_of(described) }
17
30
  it { instance.instance_variable_get('@value').must_equal(_value) }
18
- it { instance.instance_variable_get('@width').must_equal(width) }
19
31
  it { instance.instance_variable_get('@chars').must_equal(chars) }
20
32
  end
21
33
 
22
34
  describe '.render' do
23
- subject { described.render(_value, width, chars) }
35
+ subject { described.render(_value, chars) }
24
36
 
25
- # @todo Add more tests.
37
+ context 'when the title is empty' do
38
+ let(:_value) {}
39
+
40
+ it { subject.must_equal(chars) }
41
+ end
42
+
43
+ context 'when the title is not empty' do
44
+ let(:expected) {
45
+ [
46
+ Vedeu::Views::Char.new(value: '-', position: [1, 1], border: type),
47
+ Vedeu::Views::Char.new(value: ' ', position: [1, 2], border: nil),
48
+ Vedeu::Views::Char.new(value: 'A', position: [1, 3], border: nil),
49
+ Vedeu::Views::Char.new(value: 'l', position: [1, 4], border: nil),
50
+ Vedeu::Views::Char.new(value: 'u', position: [1, 5], border: nil),
51
+ Vedeu::Views::Char.new(value: 'm', position: [1, 6], border: nil),
52
+ Vedeu::Views::Char.new(value: 'i', position: [1, 7], border: nil),
53
+ Vedeu::Views::Char.new(value: 'n', position: [1, 8], border: nil),
54
+ Vedeu::Views::Char.new(value: ' ', position: [1, 9], border: nil),
55
+ Vedeu::Views::Char.new(value: '-', position: [1, 10], border: type),
56
+ ]
57
+ }
58
+
59
+ it { subject.must_equal(expected) }
60
+ end
26
61
  end
27
62
 
28
63
  describe '#eql?' do
@@ -40,22 +75,14 @@ module Vedeu
40
75
  end
41
76
 
42
77
  describe '#render' do
43
- let(:top_border) {}
44
-
45
- subject { instance.render(top_border) }
46
-
47
- context 'when the title is empty' do
48
- # @todo Add more tests.
49
- end
50
-
51
- context 'when the title is not empty' do
52
- # @todo Add more tests.
53
- end
78
+ it { instance.must_respond_to(:render) }
54
79
  end
55
80
 
56
81
  describe '#to_s' do
57
82
  subject { instance.to_s }
58
83
 
84
+ it { instance.must_respond_to(:to_str) }
85
+
59
86
  it { subject.must_equal('Aluminium') }
60
87
  end
61
88
 
@@ -147,6 +147,8 @@ module Vedeu
147
147
 
148
148
  subject { instance.to_s }
149
149
 
150
+ it { instance.must_respond_to(:to_str) }
151
+
150
152
  it { subject.must_be_instance_of(String) }
151
153
 
152
154
  it { subject.must_equal("\e[6;12H\e[?25h") }
@@ -463,6 +463,8 @@ module Vedeu
463
463
  describe '#to_s' do
464
464
  subject { instance.to_s }
465
465
 
466
+ it { instance.must_respond_to(:to_str) }
467
+
466
468
  context 'when there are no lines' do
467
469
  let(:collection) {}
468
470
 
@@ -30,6 +30,33 @@ module Vedeu
30
30
  subject { described.[](y, x) }
31
31
 
32
32
  it { instance.must_be_instance_of(described) }
33
+
34
+ context 'when the x and y coordinates are given' do
35
+ it { instance.y.must_equal(12) }
36
+ it { instance.x.must_equal(19) }
37
+ end
38
+
39
+ context 'when the x coordinate is not given' do
40
+ let(:x) {}
41
+
42
+ it { instance.y.must_equal(12) }
43
+ it { instance.x.must_equal(1) }
44
+ end
45
+
46
+ context 'when the y coordinate is not given' do
47
+ let(:y) {}
48
+
49
+ it { instance.y.must_equal(1) }
50
+ it { instance.x.must_equal(19) }
51
+ end
52
+
53
+ context 'when the x and y coordinates are not given' do
54
+ let(:x) {}
55
+ let(:y) {}
56
+
57
+ it { instance.y.must_equal(1) }
58
+ it { instance.x.must_equal(1) }
59
+ end
33
60
  end
34
61
 
35
62
  describe '#<=>' do
@@ -75,6 +102,14 @@ module Vedeu
75
102
  it { subject.x.must_equal(8) }
76
103
  end
77
104
 
105
+ context 'when the value is an Fixnum' do
106
+ let(:_value) { 2 }
107
+
108
+ it { subject.must_be_instance_of(described) }
109
+ it { subject.y.must_equal(2) }
110
+ it { subject.x.must_equal(1) }
111
+ end
112
+
78
113
  context 'when the value is a Hash' do
79
114
  let(:_value) { { y: 3, x: 9 } }
80
115
 
@@ -84,6 +119,8 @@ module Vedeu
84
119
  end
85
120
 
86
121
  context 'when the value is something unhandled' do
122
+ let(:_value) { :invalid }
123
+
87
124
  it { subject.must_be_instance_of(NilClass) }
88
125
  end
89
126
  end
@@ -103,44 +140,67 @@ module Vedeu
103
140
  end
104
141
 
105
142
  describe '#to_a' do
106
- subject { Vedeu::Geometries::Position.new.to_a }
143
+ subject { instance.to_a }
107
144
 
108
- it { subject.must_equal([1, 1]) }
145
+ it { subject.must_equal([12, 19]) }
109
146
  end
110
147
 
111
- describe '#to_position' do
112
- subject { instance.to_position }
148
+ describe '#to_h' do
149
+ subject { instance.to_h }
113
150
 
114
- it { subject.must_be_instance_of(Vedeu::Geometries::Position) }
115
- it { subject.must_equal(instance) }
151
+ it { subject.must_equal({ y: 12, x: 19 }) }
116
152
  end
117
153
 
118
154
  describe '#to_s' do
119
- # subject { described.new.to_s }
155
+ let(:_value) {}
156
+
157
+ subject { described.coerce(_value).to_s }
120
158
 
121
- it 'returns an escape sequence when no coordinates are provided' do
122
- Vedeu::Geometries::Position.new.to_s.must_equal("\e[1;1H")
159
+ context 'when no coordinates are provided' do
160
+ it { subject.must_equal('') }
123
161
  end
124
162
 
125
- it 'returns an escape sequence when coordinates are provided' do
126
- Vedeu::Geometries::Position[12, 19].to_s.must_equal("\e[12;19H")
163
+ context 'when coordinates are provided' do
164
+ let(:_value) { [12, 19] }
165
+
166
+ it 'returns an escape sequence' do
167
+ subject.must_equal("\e[12;19H")
168
+ end
127
169
  end
128
170
 
129
- it 'returns an escape sequence if a coordinate is missing' do
130
- Vedeu::Geometries::Position.new(12).to_s.must_equal("\e[12;1H")
171
+ context 'when a coordinate is missing' do
172
+ let(:_value) { 12 }
173
+
174
+ it 'returns an escape sequence' do
175
+ subject.must_equal("\e[12;1H")
176
+ end
131
177
  end
132
178
 
133
- it 'returns an escape sequence if the x coordinate is negative' do
134
- Vedeu::Geometries::Position[12, -5].to_s.must_equal("\e[12;1H")
179
+ context 'when the x coordinate is negative' do
180
+ let(:_value) { [12, -5] }
181
+
182
+ it 'returns an escape sequence' do
183
+ subject.must_equal("\e[12;1H")
184
+ end
135
185
  end
136
186
 
137
- it 'returns an escape sequence if the y coordinate is negative' do
138
- Vedeu::Geometries::Position[-12, 5].to_s.must_equal("\e[1;5H")
187
+ context 'when the y coordinate is negative' do
188
+ let(:_value) { [-12, 5] }
189
+
190
+ it 'returns an escape sequence' do
191
+ subject.must_equal("\e[1;5H")
192
+ end
139
193
  end
140
194
 
141
- it 'resets to starting position when a block is given' do
142
- Vedeu::Geometries::Position[4, 9].to_s { 'test' }.
143
- must_equal("\e[4;9Htest")
195
+ context 'when a block is given' do
196
+ let(:instance) { described.coerce(_value) }
197
+ let(:_value) { [4, 9] }
198
+
199
+ subject { instance.to_s { 'test' } }
200
+
201
+ it 'returns an escape sequence and the result of the block' do
202
+ subject.must_equal("\e[4;9Htest")
203
+ end
144
204
  end
145
205
  end
146
206
 
@@ -165,7 +225,7 @@ module Vedeu
165
225
  describe '#down' do
166
226
  subject { instance.down }
167
227
 
168
- it { subject.must_be_instance_of(Vedeu::Geometries::Position) }
228
+ it { subject.must_be_instance_of(described) }
169
229
  it { subject.y.must_equal(13) }
170
230
  it { subject.x.must_equal(19) }
171
231
 
@@ -179,7 +239,7 @@ module Vedeu
179
239
  describe '#left' do
180
240
  subject { instance.left }
181
241
 
182
- it { subject.must_be_instance_of(Vedeu::Geometries::Position) }
242
+ it { subject.must_be_instance_of(described) }
183
243
  it { subject.y.must_equal(12) }
184
244
  it { subject.x.must_equal(18) }
185
245
 
@@ -193,7 +253,7 @@ module Vedeu
193
253
  describe '#right' do
194
254
  subject { instance.right }
195
255
 
196
- it { subject.must_be_instance_of(Vedeu::Geometries::Position) }
256
+ it { subject.must_be_instance_of(described) }
197
257
  it { subject.y.must_equal(12) }
198
258
  it { subject.x.must_equal(20) }
199
259
 
@@ -207,7 +267,7 @@ module Vedeu
207
267
  describe '#up' do
208
268
  subject { instance.up }
209
269
 
210
- it { subject.must_be_instance_of(Vedeu::Geometries::Position) }
270
+ it { subject.must_be_instance_of(described) }
211
271
  it { subject.y.must_equal(11) }
212
272
  it { subject.x.must_equal(19) }
213
273
 
@@ -0,0 +1,67 @@
1
+ require 'test_helper'
2
+
3
+ module Vedeu
4
+
5
+ module Geometries
6
+
7
+ describe Positionable do
8
+
9
+ # describe '#position' do
10
+ # subject { instance.position }
11
+
12
+ # it { subject.must_be_instance_of(Vedeu::Geometries::Position) }
13
+
14
+ # # @todo Add more tests.
15
+ # end
16
+
17
+ # describe '#position=' do
18
+ # subject { instance.position=(value) }
19
+
20
+ # it { subject.must_be_instance_of(Vedeu::Geometries::Position) }
21
+
22
+ # # @todo Add more tests.
23
+ # end
24
+
25
+ # describe '#position?' do
26
+ # subject { instance.position? }
27
+
28
+ # # @todo Add more tests.
29
+ # end
30
+
31
+ # describe '#x' do
32
+ # let(:position) { Vedeu::Geometries::Position.coerce([17, 2]) }
33
+
34
+ # subject { instance.x }
35
+
36
+ # context 'when a position is set' do
37
+ # it { subject.must_equal(2) }
38
+ # end
39
+
40
+ # context 'when a position is not set' do
41
+ # let(:position) {}
42
+
43
+ # it { subject.must_equal(nil) }
44
+ # end
45
+ # end
46
+
47
+ # describe '#y' do
48
+ # let(:position) { Vedeu::Geometries::Position.coerce([17, 2]) }
49
+
50
+ # subject { instance.y }
51
+
52
+ # context 'when a position is set' do
53
+ # it { subject.must_equal(17) }
54
+ # end
55
+
56
+ # context 'when a position is not set' do
57
+ # let(:position) {}
58
+
59
+ # it { subject.must_equal(nil) }
60
+ # end
61
+ # end
62
+
63
+ end # Positionable
64
+
65
+ end # Positionable
66
+
67
+ end # Vedeu
@@ -105,6 +105,7 @@ module Vedeu
105
105
  describe '#to_s' do
106
106
  subject { instance.to_s }
107
107
 
108
+ it { instance.must_respond_to(:to_str) }
108
109
  it { subject.must_be_instance_of(String) }
109
110
  it { subject.must_equal('') }
110
111
  end
@@ -51,16 +51,6 @@ module Vedeu
51
51
  it { instance.must_respond_to(:==) }
52
52
  end
53
53
 
54
- describe '#position' do
55
- it { instance.position.must_be_instance_of(Vedeu::Geometries::Position) }
56
- end
57
-
58
- describe '#position' do
59
- subject { instance.position }
60
-
61
- it { subject.must_be_instance_of(Vedeu::Geometries::Position) }
62
- end
63
-
64
54
  describe '#value' do
65
55
  subject { instance.value }
66
56
 
@@ -54,8 +54,6 @@ module Vedeu
54
54
  " \"parent\": {\n" \
55
55
  " },\n" \
56
56
  " \"position\": {\n" \
57
- " \"y\": null,\n" \
58
- " \"x\": null\n" \
59
57
  " },\n" \
60
58
  " \"style\": \"\",\n" \
61
59
  " \"value\": \"a\"\n" \
@@ -70,8 +68,6 @@ module Vedeu
70
68
  " \"parent\": {\n" \
71
69
  " },\n" \
72
70
  " \"position\": {\n" \
73
- " \"y\": null,\n" \
74
- " \"x\": null\n" \
75
71
  " },\n" \
76
72
  " \"style\": \"\",\n" \
77
73
  " \"value\": \"\\u001b[0m\"\n" \
@@ -109,38 +109,35 @@ module Vedeu
109
109
  it { subject.must_be_instance_of(Vedeu::Interfaces::Interface) }
110
110
  end
111
111
 
112
- describe '#position' do
113
- subject { instance.position }
114
- end
115
-
116
- describe '#position=' do
117
- subject { instance.position=(value) }
118
- end
119
-
120
112
  describe '#to_hash' do
113
+ let(:position) { Vedeu::Geometries::Position.coerce([17, 2]) }
114
+ let(:expected) {
115
+ {
116
+ border: '',
117
+ colour: {
118
+ background: '',
119
+ foreground: '',
120
+ },
121
+ name: 'Vedeu::Views::Char',
122
+ parent: {
123
+ background: '',
124
+ foreground: '',
125
+ style: '',
126
+ },
127
+ position: {
128
+ y: 17,
129
+ x: 2,
130
+ },
131
+ style: '',
132
+ value: 'a',
133
+ }
134
+ }
135
+
121
136
  subject { instance.to_hash }
122
137
 
123
138
  it { subject.must_be_instance_of(Hash) }
124
139
 
125
- it { subject.must_equal(
126
- border: '',
127
- colour: {
128
- background: '',
129
- foreground: '',
130
- },
131
- name: 'Vedeu::Views::Char',
132
- parent: {
133
- background: '',
134
- foreground: '',
135
- style: '',
136
- },
137
- position: {
138
- y: nil,
139
- x: nil
140
- },
141
- style: '',
142
- value: 'a')
143
- }
140
+ it { subject.must_equal(expected) }
144
141
  end
145
142
 
146
143
  describe '#to_html' do
@@ -155,7 +152,7 @@ module Vedeu
155
152
  it { subject.must_be_instance_of(String) }
156
153
 
157
154
  context 'when a position is specified' do
158
- let(:position) { Vedeu::Geometries::Position[17, 2] }
155
+ let(:position) { Vedeu::Geometries::Position.coerce([17, 2]) }
159
156
 
160
157
  it { subject.must_equal("\e[17;2Ha") }
161
158
  end
@@ -240,38 +237,6 @@ module Vedeu
240
237
  end
241
238
  end
242
239
 
243
- describe '#x' do
244
- let(:position) { Vedeu::Geometries::Position[17, 2] }
245
-
246
- subject { instance.x }
247
-
248
- context 'when a position is set' do
249
- it { subject.must_equal(2) }
250
- end
251
-
252
- context 'when a position is not set' do
253
- let(:position) {}
254
-
255
- it { subject.must_equal(nil) }
256
- end
257
- end
258
-
259
- describe '#y' do
260
- let(:position) { Vedeu::Geometries::Position[17, 2] }
261
-
262
- subject { instance.y }
263
-
264
- context 'when a position is set' do
265
- it { subject.must_equal(17) }
266
- end
267
-
268
- context 'when a position is not set' do
269
- let(:position) {}
270
-
271
- it { subject.must_equal(nil) }
272
- end
273
- end
274
-
275
240
  end # Char
276
241
 
277
242
  end # Views
data/vedeu.gemspec CHANGED
@@ -28,7 +28,7 @@ Gem::Specification.new do |spec|
28
28
  spec.add_development_dependency 'mocha', '1.1.0'
29
29
  spec.add_development_dependency 'pry', '0.10.3'
30
30
  spec.add_development_dependency 'rubocop', '0.35.1'
31
- spec.add_development_dependency 'simplecov', '0.10.0'
31
+ spec.add_development_dependency 'simplecov', '0.11.0'
32
32
  spec.add_development_dependency 'simplecov-console', '0.2.0'
33
33
  spec.add_development_dependency 'yard', '0.8.7.6'
34
34
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vedeu
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.70
4
+ version: 0.6.71
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gavin Laking
@@ -128,14 +128,14 @@ dependencies:
128
128
  requirements:
129
129
  - - '='
130
130
  - !ruby/object:Gem::Version
131
- version: 0.10.0
131
+ version: 0.11.0
132
132
  type: :development
133
133
  prerelease: false
134
134
  version_requirements: !ruby/object:Gem::Requirement
135
135
  requirements:
136
136
  - - '='
137
137
  - !ruby/object:Gem::Version
138
- version: 0.10.0
138
+ version: 0.11.0
139
139
  - !ruby/object:Gem::Dependency
140
140
  name: simplecov-console
141
141
  requirement: !ruby/object:Gem::Requirement
@@ -433,6 +433,7 @@ files:
433
433
  - lib/vedeu/geometries/geometry.rb
434
434
  - lib/vedeu/geometries/move.rb
435
435
  - lib/vedeu/geometries/position.rb
436
+ - lib/vedeu/geometries/positionable.rb
436
437
  - lib/vedeu/geometries/repository.rb
437
438
  - lib/vedeu/groups/all.rb
438
439
  - lib/vedeu/groups/clear.rb
@@ -632,6 +633,7 @@ files:
632
633
  - test/lib/vedeu/geometries/geometry_test.rb
633
634
  - test/lib/vedeu/geometries/move_test.rb
634
635
  - test/lib/vedeu/geometries/position_test.rb
636
+ - test/lib/vedeu/geometries/positionable_test.rb
635
637
  - test/lib/vedeu/geometries/repository_test.rb
636
638
  - test/lib/vedeu/groups/clear_test.rb
637
639
  - test/lib/vedeu/groups/dsl_test.rb
@@ -857,6 +859,7 @@ test_files:
857
859
  - test/lib/vedeu/geometries/geometry_test.rb
858
860
  - test/lib/vedeu/geometries/move_test.rb
859
861
  - test/lib/vedeu/geometries/position_test.rb
862
+ - test/lib/vedeu/geometries/positionable_test.rb
860
863
  - test/lib/vedeu/geometries/repository_test.rb
861
864
  - test/lib/vedeu/groups/clear_test.rb
862
865
  - test/lib/vedeu/groups/dsl_test.rb