vedeu 0.8.4 → 0.8.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/TODO.md +4 -0
- data/docs/dsl.md +1 -11
- data/docs/dsl/by_method/geometry/align.md +1 -0
- data/docs/dsl/by_method/geometry/align_bottom.md +40 -0
- data/docs/dsl/by_method/geometry/align_centre.md +40 -0
- data/docs/dsl/by_method/geometry/align_left.md +40 -0
- data/docs/dsl/by_method/geometry/align_middle.md +40 -0
- data/docs/dsl/by_method/geometry/align_right.md +40 -0
- data/docs/dsl/by_method/geometry/align_top.md +40 -0
- data/docs/dsl/by_method/geometry/columns.md +1 -0
- data/docs/dsl/by_method/geometry/height.md +0 -0
- data/docs/dsl/by_method/geometry/horizontal_alignment.md +1 -0
- data/docs/dsl/by_method/geometry/rows.md +1 -0
- data/docs/dsl/by_method/geometry/vertical_alignment.md +1 -0
- data/docs/dsl/by_method/geometry/width.md +0 -0
- data/docs/dsl/by_method/geometry/x.md +1 -0
- data/docs/dsl/by_method/geometry/xn.md +1 -0
- data/docs/dsl/by_method/geometry/y.md +1 -0
- data/docs/dsl/by_method/geometry/yn.md +1 -0
- data/docs/dsl/by_method/render.md +5 -1
- data/docs/dsl/by_method/renders.md +31 -1
- data/docs/dsl/by_method/view.md +26 -0
- data/docs/dsl/by_method/view/stream.md +18 -0
- data/docs/dsl/by_method/views.md +32 -1
- data/docs/events/by_name/set_border_caption.md +2 -4
- data/docs/events/by_name/set_border_title.md +2 -4
- data/examples/views/empty_template.rb +0 -4
- data/examples/views/full_screen.rb +30 -5
- data/examples/views/misc_view.rb +464 -0
- data/examples/views/wordwrap.rb +72 -0
- data/examples/views/wordwrap.txt +8 -0
- data/integrations/dsl_app_021.rb +127 -0
- data/integrations/dsl_app_022.rb +133 -0
- data/integrations/expected/342_streams.out +1 -1
- data/integrations/expected/dsl_app_001.out +1 -1
- data/integrations/expected/dsl_app_002.out +1 -1
- data/integrations/expected/dsl_app_003.out +1 -1
- data/integrations/expected/dsl_app_004.out +1 -1
- data/integrations/expected/dsl_app_005.out +1 -1
- data/integrations/expected/dsl_app_006.out +1 -1
- data/integrations/expected/dsl_app_007.out +1 -1
- data/integrations/expected/dsl_app_008.out +1 -1
- data/integrations/expected/dsl_app_009.out +1 -1
- data/integrations/expected/dsl_app_010.out +1 -1
- data/integrations/expected/dsl_app_011.out +1 -1
- data/integrations/expected/dsl_app_012.out +1 -1
- data/integrations/expected/dsl_app_013.out +1 -1
- data/integrations/expected/dsl_app_014.out +1 -1
- data/integrations/expected/dsl_app_015.out +1 -1
- data/integrations/expected/dsl_app_016.out +1 -1
- data/integrations/expected/dsl_app_021.out +1 -0
- data/integrations/expected/dsl_app_022.out +1 -0
- data/integrations/support/test_interface_021.rb +7 -0
- data/integrations/support/test_interface_022.rb +15 -0
- data/lib/vedeu/all.rb +4 -2
- data/lib/vedeu/borders/border.rb +22 -6
- data/lib/vedeu/borders/repository.rb +4 -8
- data/lib/vedeu/buffers/buffer.rb +9 -6
- data/lib/vedeu/buffers/empty.rb +26 -23
- data/lib/vedeu/buffers/view.rb +44 -41
- data/lib/vedeu/cells/cursor.rb +0 -2
- data/lib/vedeu/cells/empty.rb +0 -1
- data/lib/vedeu/cells/escape.rb +0 -2
- data/lib/vedeu/coercers/alignment.rb +58 -8
- data/lib/vedeu/coercers/horizontal_alignment.rb +13 -9
- data/lib/vedeu/coercers/vertical_alignment.rb +13 -8
- data/lib/vedeu/common.rb +1 -1
- data/lib/vedeu/configuration/configuration.rb +41 -3
- data/lib/vedeu/cursors/coordinate.rb +1 -3
- data/lib/vedeu/cursors/cursor.rb +2 -6
- data/lib/vedeu/dsl/all.rb +1 -2
- data/lib/vedeu/dsl/border.rb +6 -6
- data/lib/vedeu/dsl/elements.rb +2 -2
- data/lib/vedeu/dsl/geometry.rb +7 -7
- data/lib/vedeu/dsl/{string → helpers}/align.rb +0 -0
- data/lib/vedeu/dsl/helpers/all.rb +17 -0
- data/lib/vedeu/dsl/{attributes.rb → helpers/attributes.rb} +0 -0
- data/lib/vedeu/dsl/{string → helpers}/text.rb +0 -0
- data/lib/vedeu/dsl/{string → helpers}/truncate.rb +0 -0
- data/lib/vedeu/dsl/{string → helpers}/wordwrap.rb +0 -0
- data/lib/vedeu/dsl/view.rb +11 -19
- data/lib/vedeu/dsl/views.rb +16 -106
- data/lib/vedeu/geometries/all.rb +0 -1
- data/lib/vedeu/geometries/area/area.rb +6 -12
- data/lib/vedeu/geometries/area/dimension.rb +21 -44
- data/lib/vedeu/geometries/dsl/all.rb +0 -1
- data/lib/vedeu/geometries/dsl/dsl.rb +22 -31
- data/lib/vedeu/geometries/geometry.rb +6 -0
- data/lib/vedeu/geometries/position.rb +6 -3
- data/lib/vedeu/geometries/repository.rb +1 -1
- data/lib/vedeu/input/mouse.rb +1 -0
- data/lib/vedeu/logging/log.rb +3 -6
- data/lib/vedeu/menus/dsl.rb +4 -5
- data/lib/vedeu/output/compressor.rb +11 -1
- data/lib/vedeu/output/viewport.rb +59 -59
- data/lib/vedeu/presentation/all.rb +1 -2
- data/lib/vedeu/presentation/colour.rb +75 -3
- data/lib/vedeu/{geometries/positionable.rb → presentation/position.rb} +4 -4
- data/lib/vedeu/presentation/presentation.rb +1 -3
- data/lib/vedeu/presentation/styles.rb +16 -1
- data/lib/vedeu/repositories/all.rb +0 -1
- data/lib/vedeu/sentence.rb +91 -0
- data/lib/vedeu/support/point.rb +72 -0
- data/lib/vedeu/terminal/terminal.rb +11 -53
- data/lib/vedeu/version.rb +1 -1
- data/lib/vedeu/views/composition.rb +11 -1
- data/lib/vedeu/views/default_attributes.rb +2 -0
- data/lib/vedeu/views/line.rb +16 -1
- data/lib/vedeu/views/stream.rb +16 -1
- data/lib/vedeu/views/view.rb +25 -17
- data/test/lib/vedeu/borders/border_test.rb +20 -2
- data/test/lib/vedeu/buffers/buffer_test.rb +15 -2
- data/test/lib/vedeu/buffers/empty_test.rb +51 -18
- data/test/lib/vedeu/buffers/view_test.rb +2 -2
- data/test/lib/vedeu/coercers/alignment_test.rb +32 -0
- data/test/lib/vedeu/coercers/horizontal_alignment_test.rb +16 -0
- data/test/lib/vedeu/coercers/vertical_alignment_test.rb +16 -0
- data/test/lib/vedeu/cursors/cursor_test.rb +4 -4
- data/test/lib/vedeu/cursors/dsl_test.rb +35 -21
- data/test/lib/vedeu/dsl/elements_test.rb +94 -2
- data/test/lib/vedeu/dsl/{string → helpers}/align_test.rb +0 -0
- data/test/lib/vedeu/dsl/{attributes_test.rb → helpers/attributes_test.rb} +0 -0
- data/test/lib/vedeu/dsl/{string → helpers}/text_test.rb +0 -0
- data/test/lib/vedeu/dsl/{string → helpers}/truncate_test.rb +0 -0
- data/test/lib/vedeu/dsl/{string → helpers}/wordwrap_test.rb +0 -0
- data/test/lib/vedeu/dsl/view_test.rb +22 -4
- data/test/lib/vedeu/dsl/views_test.rb +8 -5
- data/test/lib/vedeu/geometries/dsl/dsl_test.rb +2 -159
- data/test/lib/vedeu/geometries/position_test.rb +118 -60
- data/test/lib/vedeu/input/mouse_test.rb +1 -6
- data/test/lib/vedeu/logging/log_test.rb +14 -3
- data/test/lib/vedeu/presentation/colour_test.rb +77 -0
- data/test/lib/vedeu/{geometries/positionable_test.rb → presentation/position_test.rb} +4 -4
- data/test/lib/vedeu/sentence_test.rb +49 -0
- data/test/lib/vedeu/support/point_test.rb +139 -0
- data/test/lib/vedeu/terminal/terminal_test.rb +3 -44
- data/test/lib/vedeu/views/composition_test.rb +24 -4
- data/test/lib/vedeu/views/default_attributes_test.rb +10 -2
- data/test/lib/vedeu/views/view_test.rb +8 -15
- data/test/support/examples/material_colours_app.rb +0 -6
- data/vedeu.gemspec +1 -1
- metadata +58 -38
- data/examples/views/lines_line_stream.rb +0 -95
- data/examples/views/lines_line_streams.rb +0 -75
- data/examples/views/lines_line_streams_stream.rb +0 -78
- data/examples/views/lines_line_streams_stream_stream.rb +0 -50
- data/examples/views/lines_streams.rb +0 -93
- data/lib/vedeu/dsl/string/all.rb +0 -16
- data/lib/vedeu/geometries/dsl/validator.rb +0 -62
- data/lib/vedeu/presentation/background.rb +0 -54
- data/lib/vedeu/presentation/foreground.rb +0 -54
- data/lib/vedeu/repositories/parent.rb +0 -34
- data/test/lib/vedeu/geometries/dsl/validator_test.rb +0 -85
- data/test/lib/vedeu/presentation/background_test.rb +0 -74
- 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'
|
data/lib/vedeu/borders/border.rb
CHANGED
@@ -37,10 +37,10 @@ module Vedeu
|
|
37
37
|
# horizontal border if enabled.
|
38
38
|
attr_writer :bottom_horizontal
|
39
39
|
|
40
|
-
# @!attribute [
|
40
|
+
# @!attribute [r] caption
|
41
41
|
# @return [String] An optional caption for when the bottom
|
42
42
|
# border is to be shown.
|
43
|
-
|
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 [
|
74
|
+
# @!attribute [r] title
|
75
75
|
# @return [String] An optional title for when the top border is
|
76
76
|
# to be shown.
|
77
|
-
|
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:
|
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:
|
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/
|
33
|
+
# See {file:docs/events/by_name/set_border_caption.md}
|
34
34
|
Vedeu.bind(:_set_border_caption_) do |name, caption|
|
35
|
-
|
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/
|
38
|
+
# See {file:docs/events/by_name/set_border_title.md}
|
41
39
|
Vedeu.bind(:_set_border_title_) do |name, title|
|
42
|
-
|
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:
|
data/lib/vedeu/buffers/buffer.rb
CHANGED
@@ -52,17 +52,20 @@ module Vedeu
|
|
52
52
|
end
|
53
53
|
end
|
54
54
|
|
55
|
-
# Add the
|
56
|
-
#
|
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
|
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(
|
62
|
-
@back =
|
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
|
|
data/lib/vedeu/buffers/empty.rb
CHANGED
@@ -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
|
-
#
|
20
|
-
|
21
|
-
|
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
|
-
#
|
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
|
-
|
36
|
-
@height + 1
|
37
|
-
end
|
29
|
+
attr_reader :x
|
38
30
|
|
39
|
-
#
|
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
|
-
|
45
|
-
|
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
|
data/lib/vedeu/buffers/view.rb
CHANGED
@@ -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
|
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 ||=
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
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)
|
107
|
-
|
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
|
data/lib/vedeu/cells/cursor.rb
CHANGED
data/lib/vedeu/cells/empty.rb
CHANGED
data/lib/vedeu/cells/escape.rb
CHANGED
@@ -21,23 +21,30 @@ module Vedeu
|
|
21
21
|
# @return [Symbol]
|
22
22
|
attr_reader :value
|
23
23
|
|
24
|
-
# @param
|
25
|
-
# @return
|
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 [
|
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
|
-
|
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
|
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
|