Class: Vedeu::Coercers::Alignment Private
- Inherits:
-
Object
- Object
- Vedeu::Coercers::Alignment
- Includes:
- Vedeu::Common
- Defined in:
- lib/vedeu/coercers/alignment.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
The subclasses of this class, HorizontalAlignment and VerticalAlignment provide the mechanism to validate a horizontal or vertical alignment value.
Direct Known Subclasses
Instance Attribute Summary collapse
- #value ⇒ Symbol readonly private
Class Method Summary collapse
Instance Method Summary collapse
-
#bottom_aligned? ⇒ Boolean
private
Return a boolean indicating alignment was set to :bottom.
-
#centre_aligned? ⇒ Boolean
private
Return a boolean indicating alignment was set to :centre.
- #coerce ⇒ Vedeu::Coercers::Alignment private
-
#eql?(other) ⇒ Boolean
(also: #==)
private
An object is equal when its values are the same.
- #horizontal_values ⇒ Array<Symbol> private private
-
#initialize(value = :none) ⇒ Vedeu::Coercers::Alignment
constructor
private
Returns a new instance of Vedeu::Coercers::Alignment.
- #invalid? ⇒ Boolean private
-
#left_aligned? ⇒ Boolean
private
Return a boolean indicating alignment was set to :left.
-
#middle_aligned? ⇒ Boolean
private
Return a boolean indicating alignment was set to :middle.
-
#right_aligned? ⇒ Boolean
private
Return a boolean indicating alignment was set to :right.
- #to_sentence ⇒ String private private
-
#top_aligned? ⇒ Boolean
private
Return a boolean indicating alignment was set to :top.
-
#unaligned? ⇒ Boolean
private
Return a boolean indicating alignment was set to, or is :none.
-
#valid? ⇒ Boolean
private
Return a boolean indicating the value is a valid alignment.
- #valid_horizontal? ⇒ Boolean private
- #valid_type? ⇒ Boolean private private
- #valid_vertical? ⇒ Boolean private
- #validate ⇒ Boolean private
- #values ⇒ Array<Symbol> private private
- #vertical_values ⇒ Array<Symbol> private private
Methods included from Vedeu::Common
#absent?, #array?, #boolean, #boolean?, #empty_value?, #escape?, #falsy?, #hash?, #line_model?, #numeric?, #positionable?, #present?, #snake_case, #stream_model?, #string?, #symbol?, #truthy?, #view_model?
Constructor Details
#initialize(value = :none) ⇒ Vedeu::Coercers::Alignment
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Vedeu::Coercers::Alignment.
43 44 45 |
# File 'lib/vedeu/coercers/alignment.rb', line 43 def initialize(value = :none) @value = value || :none end |
Instance Attribute Details
#value ⇒ Symbol (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
22 23 24 |
# File 'lib/vedeu/coercers/alignment.rb', line 22 def value @value end |
Class Method Details
.coerce(value = :none) ⇒ Vedeu::Coercers::Alignment
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
26 27 28 29 30 |
# File 'lib/vedeu/coercers/alignment.rb', line 26 def self.coerce(value = :none) return value if value.is_a?(self) new(value).coerce end |
.validate(value) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
35 36 37 |
# File 'lib/vedeu/coercers/alignment.rb', line 35 def self.validate(value) new(value).validate end |
Instance Method Details
#bottom_aligned? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Return a boolean indicating alignment was set to :bottom.
63 64 65 |
# File 'lib/vedeu/coercers/alignment.rb', line 63 def bottom_aligned? value == :bottom end |
#centre_aligned? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Return a boolean indicating alignment was set to :centre.
70 71 72 |
# File 'lib/vedeu/coercers/alignment.rb', line 70 def centre_aligned? value == :centre end |
#coerce ⇒ Vedeu::Coercers::Alignment
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/vedeu/coercers/alignment.rb', line 48 def coerce if value == :center @value = :centre elsif invalid? @value = :none end self end |
#eql?(other) ⇒ Boolean Also known as: ==
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
An object is equal when its values are the same.
78 79 80 |
# File 'lib/vedeu/coercers/alignment.rb', line 78 def eql?(other) self.class.equal?(other.class) && value == other.value end |
#horizontal_values ⇒ Array<Symbol> (private)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
153 154 155 156 157 158 159 160 161 |
# File 'lib/vedeu/coercers/alignment.rb', line 153 def horizontal_values [ :centre, :center, :left, :none, :right, ] end |
#invalid? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
84 85 86 |
# File 'lib/vedeu/coercers/alignment.rb', line 84 def invalid? !valid? end |
#left_aligned? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Return a boolean indicating alignment was set to :left.
91 92 93 |
# File 'lib/vedeu/coercers/alignment.rb', line 91 def left_aligned? value == :left end |
#middle_aligned? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Return a boolean indicating alignment was set to :middle.
98 99 100 |
# File 'lib/vedeu/coercers/alignment.rb', line 98 def middle_aligned? value == :middle end |
#right_aligned? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Return a boolean indicating alignment was set to :right.
105 106 107 |
# File 'lib/vedeu/coercers/alignment.rb', line 105 def right_aligned? value == :right end |
#to_sentence ⇒ String (private)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
164 165 166 |
# File 'lib/vedeu/coercers/alignment.rb', line 164 def to_sentence Vedeu::Sentence.construct(values) end |
#top_aligned? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Return a boolean indicating alignment was set to :top.
112 113 114 |
# File 'lib/vedeu/coercers/alignment.rb', line 112 def top_aligned? value == :top end |
#unaligned? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Return a boolean indicating alignment was set to, or is :none.
119 120 121 |
# File 'lib/vedeu/coercers/alignment.rb', line 119 def unaligned? value == :none end |
#valid? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Return a boolean indicating the value is a valid alignment.
126 127 128 |
# File 'lib/vedeu/coercers/alignment.rb', line 126 def valid? valid_type? && values.include?(value) end |
#valid_horizontal? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
141 142 143 |
# File 'lib/vedeu/coercers/alignment.rb', line 141 def valid_horizontal? valid_type? && horizontal_values.include?(value) end |
#valid_type? ⇒ Boolean (private)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
169 170 171 |
# File 'lib/vedeu/coercers/alignment.rb', line 169 def valid_type? present?(value) && symbol?(value) end |
#valid_vertical? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
146 147 148 |
# File 'lib/vedeu/coercers/alignment.rb', line 146 def valid_vertical? valid_type? && vertical_values.include?(value) end |
#validate ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
132 133 134 135 136 137 138 |
# File 'lib/vedeu/coercers/alignment.rb', line 132 def validate return coerce if valid_horizontal? || valid_vertical? raise Vedeu::Error::InvalidSyntax, 'Missing or invalid alignment value. ' \ "Valid values are: #{to_sentence}" end |
#values ⇒ Array<Symbol> (private)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
174 175 176 |
# File 'lib/vedeu/coercers/alignment.rb', line 174 def values horizontal_values | vertical_values end |
#vertical_values ⇒ Array<Symbol> (private)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
179 180 181 182 183 184 185 186 |
# File 'lib/vedeu/coercers/alignment.rb', line 179 def vertical_values [ :bottom, :middle, :none, :top, ] end |