Class: Vedeu::Geometry::Alignment

Inherits:
Object
  • Object
show all
Defined in:
lib/vedeu/geometry/alignment.rb

Overview

Provides the mechanism to align an interface/view horizontally to the available terminal space.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value = nil) ⇒ Vedeu::Geometry::Alignment

Parameters:

  • value (NilClass|Symbol) (defaults to: nil)


18
19
20
# File 'lib/vedeu/geometry/alignment.rb', line 18

def initialize(value = nil)
  @value = value
end

Class Method Details

.align(value = nil) ⇒ Symbol

Parameters:

  • value (NilClass|Symbol) (defaults to: nil)

Returns:

  • (Symbol)


12
13
14
# File 'lib/vedeu/geometry/alignment.rb', line 12

def self.align(value = nil)
  new(value).align
end

Instance Method Details

#alignSymbol

Returns:

  • (Symbol)

Raises:



25
26
27
28
29
30
# File 'lib/vedeu/geometry/alignment.rb', line 25

def align
  return value if valid?

  fail Vedeu::Error::InvalidSyntax,
       'Cannot align as value is invalid or undefined.'.freeze
end

#align_value?Boolean (private)

Returns:

  • (Boolean)


35
36
37
# File 'lib/vedeu/geometry/alignment.rb', line 35

def align_value?
  @value.to_s.start_with?('align_')
end

#coerced_valueSymbol (private)

Returns:

  • (Symbol)


40
41
42
43
44
# File 'lib/vedeu/geometry/alignment.rb', line 40

def coerced_value
  coerced = @value.to_s.gsub!('align_', '').to_sym

  coerced == :center ? :centre : coerced
end

#none?Boolean (private)

Returns:

  • (Boolean)


47
48
49
# File 'lib/vedeu/geometry/alignment.rb', line 47

def none?
  @value.nil? || !(@value.is_a?(Symbol)) || @value == :alignment
end

#valid?Boolean (private)

Returns:

  • (Boolean)


52
53
54
# File 'lib/vedeu/geometry/alignment.rb', line 52

def valid?
  values.include?(value)
end

#valueSymbol (private)

Returns:

  • (Symbol)


57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/vedeu/geometry/alignment.rb', line 57

def value
  @_value ||= if none?
                :none

              elsif @value == :center
                :centre

              elsif align_value?
                coerced_value

              else
                @value.to_sym

              end
end

#valuesArray<Symbol> (private)

Returns:

  • (Array<Symbol>)


74
75
76
77
78
79
80
81
# File 'lib/vedeu/geometry/alignment.rb', line 74

def values
  [
    :centre,
    :left,
    :none,
    :right,
  ]
end