Class: Vedeu::DSL::Align Private

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Common
Defined in:
lib/vedeu/dsl/helpers/align.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.

Aligns a text value based on given options when building views.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value = '', options = {}) ⇒ Vedeu::DSL::Align

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:

  • value (String) (defaults to: '')
  • options (Hash) (defaults to: {})

Options Hash (options):

  • align (Symbol)
  • name (String|Symbol)
  • pad (String)
  • width (Fixnum)


29
30
31
32
# File 'lib/vedeu/dsl/helpers/align.rb', line 29

def initialize(value = '', options = {})
  @value   = value || ''
  @options = defaults.merge!(options)
end

Instance Attribute Details

#optionsHash (readonly, protected)

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:

  • (Hash)


58
59
60
# File 'lib/vedeu/dsl/helpers/align.rb', line 58

def options
  @options
end

#valueString (readonly, protected)

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)


62
63
64
# File 'lib/vedeu/dsl/helpers/align.rb', line 62

def value
  @value
end

Instance Method Details

#absent?(variable) ⇒ Boolean Originally defined in module Common

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 boolean indicating whether a variable is nil or empty.

Parameters:

  • variable (String|Symbol|Array|Fixnum)

    The variable to check.

Returns:

#alignmentVedeu::Coercers::Alignment (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.



67
68
69
# File 'lib/vedeu/dsl/helpers/align.rb', line 67

def alignment
  @_alignment ||= Vedeu::Coercers::Alignment.coerce(options[:align])
end

#become(klass, attributes) ⇒ Class Originally defined in module Common

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.

Converts one class into another.

Parameters:

  • klass (Class)

    The class to become an instance of.

  • attributes (Hash)

    The attributes of klass.

Returns:

  • (Class)

    Returns a new instance of klass.

#boolean(value) ⇒ Boolean Originally defined in module Common

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 boolean indicating the value was a boolean.

Parameters:

  • value (void)

Returns:

#boolean?(value) ⇒ Boolean Originally defined in module Common

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 boolean indicating whether the value is a Boolean.

Parameters:

Returns:

#centreString (private) Also known as: center

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.

The value padded to width, centralized.

Returns:

  • (String)


74
75
76
# File 'lib/vedeu/dsl/helpers/align.rb', line 74

def centre
  value.center(width, options[:pad])
end

#defaultsHash (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:

  • (Hash)


80
81
82
83
84
85
86
87
# File 'lib/vedeu/dsl/helpers/align.rb', line 80

def defaults
  {
    align: :left,
    name:  nil,
    pad:   ' ',
    width: nil,
  }
end

#escape?(value) ⇒ Boolean Originally defined in module Common

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 boolean indicating whether the value is an escape sequence object (e.g. Vedeu::Cells::Escape.)

Returns:

#falsy?(value) ⇒ Boolean Originally defined in module Common

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 boolean indicating whether the value should be considered false.

Parameters:

  • value (void)

Returns:

#geometryNilClass|Vedeu::Geometries::Geometry (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:



90
91
92
# File 'lib/vedeu/dsl/helpers/align.rb', line 90

def geometry
  @_geometry ||= Vedeu.geometries.by_name(options[:name])
end

#hash?(value) ⇒ Boolean Originally defined in module Common

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 boolean indicating whether the value is a Hash.

Parameters:

  • value (Hash|void)

Returns:

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

The value padded to width, left justified. See #width.

Returns:

  • (String)


97
98
99
# File 'lib/vedeu/dsl/helpers/align.rb', line 97

def left
  value.ljust(width, options[:pad])
end

#line_model?Boolean Originally defined in module Common

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 boolean indicating the model is a Views::Line.

Returns:

#numeric?(value) ⇒ Boolean Originally defined in module Common

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 boolean indicating whether the value is a Fixnum.

Parameters:

  • value (Fixnum|void)

Returns:

#present?(variable) ⇒ Boolean Originally defined in module Common

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 boolean indicating whether a variable has a useful value.

Parameters:

  • variable (String|Symbol|Array|Fixnum)

    The variable to check.

Returns:

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

The value padded to width, right justified.

Returns:

  • (String)


104
105
106
# File 'lib/vedeu/dsl/helpers/align.rb', line 104

def right
  value.rjust(width, options[:pad])
end

#snake_case(klass) ⇒ String Originally defined in module Common

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.

Converts a class name to a lowercase snake case string.

Examples:

snake_case(MyClassName) # => "my_class_name"
snake_case(NameSpaced::ClassName)
# => "name_spaced/class_name"

snake_case('MyClassName') # => "my_class_name"
snake_case(NameSpaced::ClassName)
# => "name_spaced/class_name"

Parameters:

  • klass (Module|Class|String)

Returns:

  • (String)

#stream_model?Boolean Originally defined in module Common

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 boolean indicating the model is a Views::Stream.

Returns:

#string?(value) ⇒ Boolean Originally defined in module Common

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 boolean indicating whether the value is a Fixnum.

Parameters:

  • value (String|void)

Returns:

#textString

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)


35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/vedeu/dsl/helpers/align.rb', line 35

def text
  if unaligned?
    value

  elsif left_aligned?
    left

  elsif centre_aligned?
    centre

  elsif right_aligned?
    right

  else
    value

  end
end

#truthy?(value) ⇒ Boolean Originally defined in module Common

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 boolean indicating whether the value should be considered true.

Parameters:

  • value (void)

Returns:

#view_model?Boolean Originally defined in module Common

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 boolean indicating the model is a Views::View.

Returns:

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

Return the width given in the options. If no :width option was set, but a :name option was set, then we can use the width of the interface to determine the correct width to use. There is a caveat in this; if the :align option was set to :left, but no :width provided, then we don’t want to use the interface’s width. The reason being, is that there may be another stream in this line which will not appear by default as it will be push right out of the visible area.

Return the width of the interface when a name is given, otherwise use the given width.

Returns:

  • (Fixnum)


121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/vedeu/dsl/helpers/align.rb', line 121

def width
  if present?(options[:width])
    options[:width]

  elsif present?(options[:name])
    if left_aligned?
      value.size

    else
      geometry.bordered_width

    end

  else
    value.size

  end
end