Class: Vedeu::Coercers::Alignment Private

Inherits:
Object
  • Object
show all
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

HorizontalAlignment, VerticalAlignment

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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.

Parameters:



43
44
45
# File 'lib/vedeu/coercers/alignment.rb', line 43

def initialize(value = :none)
  @value = value || :none
end

Instance Attribute Details

#valueSymbol (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.

Returns:

  • (Symbol)


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.

Parameters:

Returns:



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.

Parameters:

Returns:

Raises:

  • (Vedeu::Error::InvalidSyntax)

    When the value given for an argument or parameter cannot be used because it is not valid for the use case, unsupported or the method expects a different type.



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.

Returns:



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.

Returns:



70
71
72
# File 'lib/vedeu/coercers/alignment.rb', line 70

def centre_aligned?
  value == :centre
end

#coerceVedeu::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.

Parameters:

  • other (void)

Returns:



78
79
80
# File 'lib/vedeu/coercers/alignment.rb', line 78

def eql?(other)
  self.class.equal?(other.class) && value == other.value
end

#horizontal_valuesArray<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.

Returns:

  • (Array<Symbol>)


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.

Returns:



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.

Returns:



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.

Returns:



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.

Returns:



105
106
107
# File 'lib/vedeu/coercers/alignment.rb', line 105

def right_aligned?
  value == :right
end

#to_sentenceString (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.

Returns:

  • (String)


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.

Returns:



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.

Returns:



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.

Returns:



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.

Returns:



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.

Returns:



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.

Returns:



146
147
148
# File 'lib/vedeu/coercers/alignment.rb', line 146

def valid_vertical?
  valid_type? && vertical_values.include?(value)
end

#validateBoolean

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:

Raises:

  • (Vedeu::Error::InvalidSyntax)

    When the value given for an argument or parameter cannot be used because it is not valid for the use case, unsupported or the method expects a different type.



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

#valuesArray<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.

Returns:

  • (Array<Symbol>)


174
175
176
# File 'lib/vedeu/coercers/alignment.rb', line 174

def values
  horizontal_values | vertical_values
end

#vertical_valuesArray<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.

Returns:

  • (Array<Symbol>)


179
180
181
182
183
184
185
186
# File 'lib/vedeu/coercers/alignment.rb', line 179

def vertical_values
  [
    :bottom,
    :middle,
    :none,
    :top,
  ]
end