vedeu 0.8.4 → 0.8.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (156) hide show
  1. checksums.yaml +4 -4
  2. data/TODO.md +4 -0
  3. data/docs/dsl.md +1 -11
  4. data/docs/dsl/by_method/geometry/align.md +1 -0
  5. data/docs/dsl/by_method/geometry/align_bottom.md +40 -0
  6. data/docs/dsl/by_method/geometry/align_centre.md +40 -0
  7. data/docs/dsl/by_method/geometry/align_left.md +40 -0
  8. data/docs/dsl/by_method/geometry/align_middle.md +40 -0
  9. data/docs/dsl/by_method/geometry/align_right.md +40 -0
  10. data/docs/dsl/by_method/geometry/align_top.md +40 -0
  11. data/docs/dsl/by_method/geometry/columns.md +1 -0
  12. data/docs/dsl/by_method/geometry/height.md +0 -0
  13. data/docs/dsl/by_method/geometry/horizontal_alignment.md +1 -0
  14. data/docs/dsl/by_method/geometry/rows.md +1 -0
  15. data/docs/dsl/by_method/geometry/vertical_alignment.md +1 -0
  16. data/docs/dsl/by_method/geometry/width.md +0 -0
  17. data/docs/dsl/by_method/geometry/x.md +1 -0
  18. data/docs/dsl/by_method/geometry/xn.md +1 -0
  19. data/docs/dsl/by_method/geometry/y.md +1 -0
  20. data/docs/dsl/by_method/geometry/yn.md +1 -0
  21. data/docs/dsl/by_method/render.md +5 -1
  22. data/docs/dsl/by_method/renders.md +31 -1
  23. data/docs/dsl/by_method/view.md +26 -0
  24. data/docs/dsl/by_method/view/stream.md +18 -0
  25. data/docs/dsl/by_method/views.md +32 -1
  26. data/docs/events/by_name/set_border_caption.md +2 -4
  27. data/docs/events/by_name/set_border_title.md +2 -4
  28. data/examples/views/empty_template.rb +0 -4
  29. data/examples/views/full_screen.rb +30 -5
  30. data/examples/views/misc_view.rb +464 -0
  31. data/examples/views/wordwrap.rb +72 -0
  32. data/examples/views/wordwrap.txt +8 -0
  33. data/integrations/dsl_app_021.rb +127 -0
  34. data/integrations/dsl_app_022.rb +133 -0
  35. data/integrations/expected/342_streams.out +1 -1
  36. data/integrations/expected/dsl_app_001.out +1 -1
  37. data/integrations/expected/dsl_app_002.out +1 -1
  38. data/integrations/expected/dsl_app_003.out +1 -1
  39. data/integrations/expected/dsl_app_004.out +1 -1
  40. data/integrations/expected/dsl_app_005.out +1 -1
  41. data/integrations/expected/dsl_app_006.out +1 -1
  42. data/integrations/expected/dsl_app_007.out +1 -1
  43. data/integrations/expected/dsl_app_008.out +1 -1
  44. data/integrations/expected/dsl_app_009.out +1 -1
  45. data/integrations/expected/dsl_app_010.out +1 -1
  46. data/integrations/expected/dsl_app_011.out +1 -1
  47. data/integrations/expected/dsl_app_012.out +1 -1
  48. data/integrations/expected/dsl_app_013.out +1 -1
  49. data/integrations/expected/dsl_app_014.out +1 -1
  50. data/integrations/expected/dsl_app_015.out +1 -1
  51. data/integrations/expected/dsl_app_016.out +1 -1
  52. data/integrations/expected/dsl_app_021.out +1 -0
  53. data/integrations/expected/dsl_app_022.out +1 -0
  54. data/integrations/support/test_interface_021.rb +7 -0
  55. data/integrations/support/test_interface_022.rb +15 -0
  56. data/lib/vedeu/all.rb +4 -2
  57. data/lib/vedeu/borders/border.rb +22 -6
  58. data/lib/vedeu/borders/repository.rb +4 -8
  59. data/lib/vedeu/buffers/buffer.rb +9 -6
  60. data/lib/vedeu/buffers/empty.rb +26 -23
  61. data/lib/vedeu/buffers/view.rb +44 -41
  62. data/lib/vedeu/cells/cursor.rb +0 -2
  63. data/lib/vedeu/cells/empty.rb +0 -1
  64. data/lib/vedeu/cells/escape.rb +0 -2
  65. data/lib/vedeu/coercers/alignment.rb +58 -8
  66. data/lib/vedeu/coercers/horizontal_alignment.rb +13 -9
  67. data/lib/vedeu/coercers/vertical_alignment.rb +13 -8
  68. data/lib/vedeu/common.rb +1 -1
  69. data/lib/vedeu/configuration/configuration.rb +41 -3
  70. data/lib/vedeu/cursors/coordinate.rb +1 -3
  71. data/lib/vedeu/cursors/cursor.rb +2 -6
  72. data/lib/vedeu/dsl/all.rb +1 -2
  73. data/lib/vedeu/dsl/border.rb +6 -6
  74. data/lib/vedeu/dsl/elements.rb +2 -2
  75. data/lib/vedeu/dsl/geometry.rb +7 -7
  76. data/lib/vedeu/dsl/{string → helpers}/align.rb +0 -0
  77. data/lib/vedeu/dsl/helpers/all.rb +17 -0
  78. data/lib/vedeu/dsl/{attributes.rb → helpers/attributes.rb} +0 -0
  79. data/lib/vedeu/dsl/{string → helpers}/text.rb +0 -0
  80. data/lib/vedeu/dsl/{string → helpers}/truncate.rb +0 -0
  81. data/lib/vedeu/dsl/{string → helpers}/wordwrap.rb +0 -0
  82. data/lib/vedeu/dsl/view.rb +11 -19
  83. data/lib/vedeu/dsl/views.rb +16 -106
  84. data/lib/vedeu/geometries/all.rb +0 -1
  85. data/lib/vedeu/geometries/area/area.rb +6 -12
  86. data/lib/vedeu/geometries/area/dimension.rb +21 -44
  87. data/lib/vedeu/geometries/dsl/all.rb +0 -1
  88. data/lib/vedeu/geometries/dsl/dsl.rb +22 -31
  89. data/lib/vedeu/geometries/geometry.rb +6 -0
  90. data/lib/vedeu/geometries/position.rb +6 -3
  91. data/lib/vedeu/geometries/repository.rb +1 -1
  92. data/lib/vedeu/input/mouse.rb +1 -0
  93. data/lib/vedeu/logging/log.rb +3 -6
  94. data/lib/vedeu/menus/dsl.rb +4 -5
  95. data/lib/vedeu/output/compressor.rb +11 -1
  96. data/lib/vedeu/output/viewport.rb +59 -59
  97. data/lib/vedeu/presentation/all.rb +1 -2
  98. data/lib/vedeu/presentation/colour.rb +75 -3
  99. data/lib/vedeu/{geometries/positionable.rb → presentation/position.rb} +4 -4
  100. data/lib/vedeu/presentation/presentation.rb +1 -3
  101. data/lib/vedeu/presentation/styles.rb +16 -1
  102. data/lib/vedeu/repositories/all.rb +0 -1
  103. data/lib/vedeu/sentence.rb +91 -0
  104. data/lib/vedeu/support/point.rb +72 -0
  105. data/lib/vedeu/terminal/terminal.rb +11 -53
  106. data/lib/vedeu/version.rb +1 -1
  107. data/lib/vedeu/views/composition.rb +11 -1
  108. data/lib/vedeu/views/default_attributes.rb +2 -0
  109. data/lib/vedeu/views/line.rb +16 -1
  110. data/lib/vedeu/views/stream.rb +16 -1
  111. data/lib/vedeu/views/view.rb +25 -17
  112. data/test/lib/vedeu/borders/border_test.rb +20 -2
  113. data/test/lib/vedeu/buffers/buffer_test.rb +15 -2
  114. data/test/lib/vedeu/buffers/empty_test.rb +51 -18
  115. data/test/lib/vedeu/buffers/view_test.rb +2 -2
  116. data/test/lib/vedeu/coercers/alignment_test.rb +32 -0
  117. data/test/lib/vedeu/coercers/horizontal_alignment_test.rb +16 -0
  118. data/test/lib/vedeu/coercers/vertical_alignment_test.rb +16 -0
  119. data/test/lib/vedeu/cursors/cursor_test.rb +4 -4
  120. data/test/lib/vedeu/cursors/dsl_test.rb +35 -21
  121. data/test/lib/vedeu/dsl/elements_test.rb +94 -2
  122. data/test/lib/vedeu/dsl/{string → helpers}/align_test.rb +0 -0
  123. data/test/lib/vedeu/dsl/{attributes_test.rb → helpers/attributes_test.rb} +0 -0
  124. data/test/lib/vedeu/dsl/{string → helpers}/text_test.rb +0 -0
  125. data/test/lib/vedeu/dsl/{string → helpers}/truncate_test.rb +0 -0
  126. data/test/lib/vedeu/dsl/{string → helpers}/wordwrap_test.rb +0 -0
  127. data/test/lib/vedeu/dsl/view_test.rb +22 -4
  128. data/test/lib/vedeu/dsl/views_test.rb +8 -5
  129. data/test/lib/vedeu/geometries/dsl/dsl_test.rb +2 -159
  130. data/test/lib/vedeu/geometries/position_test.rb +118 -60
  131. data/test/lib/vedeu/input/mouse_test.rb +1 -6
  132. data/test/lib/vedeu/logging/log_test.rb +14 -3
  133. data/test/lib/vedeu/presentation/colour_test.rb +77 -0
  134. data/test/lib/vedeu/{geometries/positionable_test.rb → presentation/position_test.rb} +4 -4
  135. data/test/lib/vedeu/sentence_test.rb +49 -0
  136. data/test/lib/vedeu/support/point_test.rb +139 -0
  137. data/test/lib/vedeu/terminal/terminal_test.rb +3 -44
  138. data/test/lib/vedeu/views/composition_test.rb +24 -4
  139. data/test/lib/vedeu/views/default_attributes_test.rb +10 -2
  140. data/test/lib/vedeu/views/view_test.rb +8 -15
  141. data/test/support/examples/material_colours_app.rb +0 -6
  142. data/vedeu.gemspec +1 -1
  143. metadata +58 -38
  144. data/examples/views/lines_line_stream.rb +0 -95
  145. data/examples/views/lines_line_streams.rb +0 -75
  146. data/examples/views/lines_line_streams_stream.rb +0 -78
  147. data/examples/views/lines_line_streams_stream_stream.rb +0 -50
  148. data/examples/views/lines_streams.rb +0 -93
  149. data/lib/vedeu/dsl/string/all.rb +0 -16
  150. data/lib/vedeu/geometries/dsl/validator.rb +0 -62
  151. data/lib/vedeu/presentation/background.rb +0 -54
  152. data/lib/vedeu/presentation/foreground.rb +0 -54
  153. data/lib/vedeu/repositories/parent.rb +0 -34
  154. data/test/lib/vedeu/geometries/dsl/validator_test.rb +0 -85
  155. data/test/lib/vedeu/presentation/background_test.rb +0 -74
  156. data/test/lib/vedeu/presentation/foreground_test.rb +0 -75
data/lib/vedeu/all.rb CHANGED
@@ -1,10 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'vedeu/version'
4
-
5
3
  require 'vedeu/boolean'
6
4
  require 'vedeu/common'
7
5
  require 'vedeu/error'
6
+ require 'vedeu/sentence'
7
+ require 'vedeu/version'
8
+
9
+ require 'vedeu/support/point'
8
10
 
9
11
  require 'vedeu/configuration/all'
10
12
  require 'vedeu/esc/all'
@@ -37,10 +37,10 @@ module Vedeu
37
37
  # horizontal border if enabled.
38
38
  attr_writer :bottom_horizontal
39
39
 
40
- # @!attribute [rw] caption
40
+ # @!attribute [r] caption
41
41
  # @return [String] An optional caption for when the bottom
42
42
  # border is to be shown.
43
- attr_accessor :caption
43
+ attr_reader :caption
44
44
 
45
45
  # @!attribute [rw] horizontal
46
46
  # @return [String] The character to be used for the horizontal
@@ -71,10 +71,10 @@ module Vedeu
71
71
  attr_accessor :show_top
72
72
  alias_method :top?, :show_top
73
73
 
74
- # @!attribute [rw] title
74
+ # @!attribute [r] title
75
75
  # @return [String] An optional title for when the top border is
76
76
  # to be shown.
77
- attr_accessor :title
77
+ attr_reader :title
78
78
 
79
79
  # @!attribute [w] top_left
80
80
  # @return [String] The character to be used for the top left
@@ -177,7 +177,7 @@ module Vedeu
177
177
  bottom_horizontal: bottom_horizontal,
178
178
  bottom_left: bottom_left,
179
179
  bottom_right: bottom_right,
180
- caption: @caption,
180
+ caption: caption,
181
181
  client: @client,
182
182
  colour: colour,
183
183
  enabled: @enabled,
@@ -192,7 +192,7 @@ module Vedeu
192
192
  show_right: @show_right,
193
193
  show_top: @show_top,
194
194
  style: style,
195
- title: @title,
195
+ title: title,
196
196
  top_horizontal: top_horizontal,
197
197
  top_left: top_left,
198
198
  top_right: top_right,
@@ -200,6 +200,14 @@ module Vedeu
200
200
  }
201
201
  end
202
202
 
203
+ # @param value [String]
204
+ # @return [Vedeu::Borders::Border]
205
+ def caption=(value)
206
+ @caption = value
207
+
208
+ store
209
+ end
210
+
203
211
  # Returns a DSL instance responsible for defining the DSL
204
212
  # methods of this model.
205
213
  #
@@ -277,6 +285,14 @@ module Vedeu
277
285
  @bottom_right ||= Vedeu::Cells::BottomRight.new(cell_attributes)
278
286
  end
279
287
 
288
+ # @param value [String]
289
+ # @return [Vedeu::Borders::Border]
290
+ def title=(value)
291
+ @title = value
292
+
293
+ store
294
+ end
295
+
280
296
  private
281
297
 
282
298
  # @return [Hash<Symbol => void>]
@@ -30,18 +30,14 @@ module Vedeu
30
30
 
31
31
  # :nocov:
32
32
 
33
- # See {file:docs/borders.md#label-3A_set_border_caption_}
33
+ # See {file:docs/events/by_name/set_border_caption.md}
34
34
  Vedeu.bind(:_set_border_caption_) do |name, caption|
35
- if Vedeu.borders.registered?(name)
36
- Vedeu.borders.by_name(name).caption = caption
37
- end
35
+ Vedeu.borders.by_name(name).caption = caption
38
36
  end
39
37
 
40
- # See {file:docs/borders.md#label-3A_set_border_title_}
38
+ # See {file:docs/events/by_name/set_border_title.md}
41
39
  Vedeu.bind(:_set_border_title_) do |name, title|
42
- if Vedeu.borders.registered?(name)
43
- Vedeu.borders.by_name(name).title = title
44
- end
40
+ Vedeu.borders.by_name(name).title = title
45
41
  end
46
42
 
47
43
  # :nocov:
@@ -52,17 +52,20 @@ module Vedeu
52
52
  end
53
53
  end
54
54
 
55
- # Add the content to the back buffer, then update the
56
- # repository. Returns boolean indicating that the repository was
57
- # updated.
55
+ # Add the view to the back buffer, then update the repository.
56
+ # Returns boolean indicating that the repository was updated.
58
57
  #
59
- # @param content [Vedeu::Views::View]
58
+ # @param view [Vedeu::Views::View]
59
+ # @param refresh [Boolean] Should the view be refreshed once
60
+ # stored? Default: false.
60
61
  # @return [Boolean]
61
- def add(content)
62
- @back = content
62
+ def add(view, refresh = false)
63
+ @back = view
63
64
 
64
65
  store
65
66
 
67
+ Vedeu.trigger(:_refresh_view_, view.name) if boolean(refresh)
68
+
66
69
  true
67
70
  end
68
71
 
@@ -12,37 +12,29 @@ module Vedeu
12
12
 
13
13
  include Vedeu::Repositories::Defaults
14
14
 
15
+ # @!attribute [r] height
16
+ # @return [Fixnum]
17
+ attr_reader :height
18
+
15
19
  # @!attribute [r] name
16
20
  # @return [NilClass|String|Symbol]
17
21
  attr_reader :name
18
22
 
19
- # @return [Array<Array<Vedeu::Cells::Empty>>]
20
- def buffer
21
- Array.new(height) do |y|
22
- if y > 0
23
- Array.new(width) do |x|
24
- Vedeu::Cells::Empty.new(name: name, position: [y, x]) if x > 0
25
- end.compact
26
- end
27
- end.compact
28
- end
23
+ # @!attribute [r] width
24
+ # @return [Fixnum]
25
+ attr_reader :width
29
26
 
30
- # @note
31
- # We add 1 to both the width and height as terminal screens
32
- # are 1-indexed.
33
- #
27
+ # @!attribute [r] x
34
28
  # @return [Fixnum]
35
- def height
36
- @height + 1
37
- end
29
+ attr_reader :x
38
30
 
39
- # @note
40
- # We add 1 to both the width and height as terminal screens
41
- # are 1-indexed.
42
- #
31
+ # @!attribute [r] y
43
32
  # @return [Fixnum]
44
- def width
45
- @width + 1
33
+ attr_reader :y
34
+
35
+ # @return [Array<Array<Vedeu::Cells::Empty>>]
36
+ def buffer
37
+ @buffer ||= empty
46
38
  end
47
39
 
48
40
  private
@@ -55,9 +47,20 @@ module Vedeu
55
47
  height: Vedeu.height,
56
48
  name: nil,
57
49
  width: Vedeu.width,
50
+ x: 1,
51
+ y: 1,
58
52
  }
59
53
  end
60
54
 
55
+ # @return [Array<Array<Vedeu::Cells::Empty>>]
56
+ def empty
57
+ Array.new(height) do |h|
58
+ Array.new(width) do |w|
59
+ Vedeu::Cells::Empty.new(name: name, position: [y + h, x + w])
60
+ end
61
+ end
62
+ end
63
+
61
64
  end # Empty
62
65
 
63
66
  end # Buffers
@@ -12,6 +12,15 @@ module Vedeu
12
12
 
13
13
  include Vedeu::Repositories::Defaults
14
14
  include Enumerable
15
+ extend Forwardable
16
+
17
+ def_delegators :geometry,
18
+ :bordered_height,
19
+ :bordered_width,
20
+ :bx,
21
+ :by,
22
+ :byn,
23
+ :bxn
15
24
 
16
25
  # @return [Hash<Symbol => String|Symbol>]
17
26
  def attributes
@@ -39,12 +48,7 @@ module Vedeu
39
48
  # Vedeu::Cells::Char]
40
49
  # @return [Vedeu::Buffers::View]
41
50
  def update(value_or_values)
42
- Array(value_or_values).flatten.each do |value|
43
- if valid?(value)
44
- current[value.position.y][value.position.x] = value
45
- dirty << value.position.to_a
46
- end
47
- end
51
+ Array(value_or_values).flatten.each { |value| write(value) }
48
52
 
49
53
  self
50
54
  end
@@ -57,41 +61,22 @@ module Vedeu
57
61
 
58
62
  private
59
63
 
60
- # @return [Vedeu::Buffers::Empty]
61
- def buffer
62
- @_buffer ||= Vedeu::Buffers::Empty
63
- .new(height: geometry.bordered_height,
64
- name: name,
65
- width: geometry.bordered_width).buffer
66
- end
67
-
68
64
  # @return [Array<Vedeu::Cells::Empty>]
69
65
  def current
70
- @current ||= buffer
71
- end
72
-
73
- # @return [Vedeu::Buffers::Empty]
74
- def current_reset!
75
- @current = buffer
66
+ @current ||= Vedeu::Buffers::Empty.new(height: bordered_height,
67
+ name: name,
68
+ width: bordered_width,
69
+ x: bx,
70
+ y: by).buffer
76
71
  end
77
72
 
78
73
  # @return [Hash<Symbol => NilClass|String|Symbol]
79
74
  def defaults
80
75
  {
81
- name: ''
76
+ name: nil
82
77
  }
83
78
  end
84
79
 
85
- # @return [Vedeu::Buffers::Empty]
86
- def dirty
87
- @dirty ||= []
88
- end
89
-
90
- # @return [Vedeu::Buffers::Empty]
91
- def dirty_reset!
92
- @dirty = []
93
- end
94
-
95
80
  # @return [Vedeu::Geometries::Geometry]
96
81
  def geometry
97
82
  @_geometry ||= Vedeu.geometries.by_name(name)
@@ -103,16 +88,9 @@ module Vedeu
103
88
  # @param value [void]
104
89
  # @return [Boolean]
105
90
  def valid?(value)
106
- valid_value?(value) && valid_position?(value)
107
- end
108
-
109
- # Returns a boolean indicating whether the position of the value
110
- # object is valid for this terminal.
111
- #
112
- # @param value [void]
113
- # @return [Boolean]
114
- def valid_position?(value)
115
- buffer[value.position.y] && buffer[value.position.y][value.position.x]
91
+ valid_value?(value) &&
92
+ valid_y?(value.position.y) &&
93
+ valid_x?(value.position.x)
116
94
  end
117
95
 
118
96
  # Returns a boolean indicating the value has a position
@@ -125,6 +103,31 @@ module Vedeu
125
103
  value.position.is_a?(Vedeu::Geometries::Position)
126
104
  end
127
105
 
106
+ # Returns a boolean indicating whether the x position of the
107
+ # value object is valid for this geometry.
108
+ #
109
+ # @return [Boolean]
110
+ def valid_x?(x)
111
+ Vedeu::Point.valid?(value: x, min: bx, max: bxn)
112
+ end
113
+
114
+ # Returns a boolean indicating whether the y position of the
115
+ # value object is valid for this geometry.
116
+ #
117
+ # @return [Boolean]
118
+ def valid_y?(y)
119
+ Vedeu::Point.valid?(value: y, min: by, max: byn)
120
+ end
121
+
122
+ def write(value)
123
+ if valid?(value)
124
+ row = by - value.position.y
125
+ column = bx - value.position.x
126
+
127
+ current[row][column] = value
128
+ end
129
+ end
130
+
128
131
  end # View
129
132
 
130
133
  end # Buffers
@@ -11,8 +11,6 @@ module Vedeu
11
11
  #
12
12
  class Cursor < Vedeu::Cells::Empty
13
13
 
14
- include Vedeu::Geometries::Positionable
15
-
16
14
  # @return [Boolean]
17
15
  def cell?
18
16
  false
@@ -14,7 +14,6 @@ module Vedeu
14
14
  #
15
15
  class Empty
16
16
 
17
- include Comparable
18
17
  include Vedeu::Presentation
19
18
  include Vedeu::Repositories::Defaults
20
19
 
@@ -19,8 +19,6 @@ module Vedeu
19
19
  #
20
20
  class Escape < Vedeu::Cells::Empty
21
21
 
22
- include Vedeu::Geometries::Positionable
23
-
24
22
  # @return [Boolean]
25
23
  def cell?
26
24
  false
@@ -21,23 +21,30 @@ module Vedeu
21
21
  # @return [Symbol]
22
22
  attr_reader :value
23
23
 
24
- # @param value [Symbol|Vedeu::Coercers::Alignment]
25
- # @return [Vedeu::Coercers::Alignment]
24
+ # @param (see #initialize)
25
+ # @return (see #coerce)
26
26
  def self.coerce(value = :none)
27
27
  return value if value.is_a?(self)
28
28
 
29
29
  new(value).coerce
30
30
  end
31
31
 
32
+ # @param (see #initialize)
33
+ # @raise (see #validate)
34
+ # @return (see #validate)
35
+ def self.validate(value)
36
+ new(value).validate
37
+ end
38
+
32
39
  # Returns a new instance of Vedeu::Coercers::Alignment.
33
40
  #
34
- # @param value [Symbol]
41
+ # @param value [Symbol|Vedeu::Coercers::Alignment]
35
42
  # @return [Vedeu::Coercers::Alignment]
36
43
  def initialize(value = :none)
37
44
  @value = value || :none
38
45
  end
39
46
 
40
- # @return [Symbol]
47
+ # @return [Vedeu::Coercers::Alignment]
41
48
  def coerce
42
49
  if value == :center
43
50
  @value = :centre
@@ -117,21 +124,64 @@ module Vedeu
117
124
  #
118
125
  # @return [Boolean]
119
126
  def valid?
120
- present?(value) && value.is_a?(Symbol) && values.include?(value)
127
+ valid_type? && values.include?(value)
128
+ end
129
+
130
+ # @raise [Vedeu::Error::InvalidSyntax] When the value is missing or
131
+ # invalid.
132
+ # @return [Boolean]
133
+ def validate
134
+ return coerce if valid_horizontal? || valid_vertical?
135
+
136
+ fail Vedeu::Error::InvalidSyntax,
137
+ 'Missing or invalid alignment value. ' \
138
+ "Valid values are: #{to_sentence}"
139
+ end
140
+
141
+ # @return [Boolean]
142
+ def valid_horizontal?
143
+ valid_type? && horizontal_values.include?(value)
144
+ end
145
+
146
+ # @return [Boolean]
147
+ def valid_vertical?
148
+ valid_type? && vertical_values.include?(value)
121
149
  end
122
150
 
123
151
  private
124
152
 
125
153
  # @return [Array<Symbol>]
126
- def values
154
+ def horizontal_values
127
155
  [
128
- :bottom,
129
156
  :centre,
130
157
  :center,
131
158
  :left,
132
- :middle,
133
159
  :none,
134
160
  :right,
161
+ ]
162
+ end
163
+
164
+ # @return [String]
165
+ def to_sentence
166
+ Vedeu::Sentence.construct(values)
167
+ end
168
+
169
+ # @return [Boolean]
170
+ def valid_type?
171
+ present?(value) && value.is_a?(Symbol)
172
+ end
173
+
174
+ # @return [Array<Symbol>]
175
+ def values
176
+ horizontal_values | vertical_values
177
+ end
178
+
179
+ # @return [Array<Symbol>]
180
+ def vertical_values
181
+ [
182
+ :bottom,
183
+ :middle,
184
+ :none,
135
185
  :top,
136
186
  ]
137
187
  end