Class: Vedeu::DSL::Text Private

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

Manipulates text values based on given options when building views.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

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:



19
20
21
22
# File 'lib/vedeu/dsl/helpers/text.rb', line 19

def initialize(value = '', options = {})
  @value   = value   || ''
  @options = options || {}
end

Instance Attribute Details

#optionsHash<Symbol => void> (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<Symbol => void>)


35
36
37
# File 'lib/vedeu/dsl/helpers/text.rb', line 35

def options
  @options
end

#valueNilClass|String (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:

  • (NilClass|String)


39
40
41
# File 'lib/vedeu/dsl/helpers/text.rb', line 39

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:

#alignString (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)


44
45
46
# File 'lib/vedeu/dsl/helpers/text.rb', line 44

def align
  Vedeu::DSL::Align.new(value, options).text
end

#align?NilClass|Vedeu::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.

Returns:



49
50
51
# File 'lib/vedeu/dsl/helpers/text.rb', line 49

def align?
  options[:align]
end

#attributes(char) ⇒ Hash<Symbol => void> (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.

Parameters:

  • char (String)

Returns:

  • (Hash<Symbol => void>)


55
56
57
58
59
60
61
62
63
64
# File 'lib/vedeu/dsl/helpers/text.rb', line 55

def attributes(char)
  {
    colour:   options[:colour],
    name:     name,
    parent:   parent,
    position: nil,
    style:    options[:style],
    value:    char,
  }
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:

#charsArray<Vedeu::Cells::Char>

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:



25
26
27
28
29
# File 'lib/vedeu/dsl/helpers/text.rb', line 25

def chars
  return [] unless present?(value) && string?(value)

  collection
end

#collectionArray<Vedeu::Cells::Char> (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:



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

def collection
  text.chars.map { |char| Vedeu::Cells::Char.new(attributes(char)) }
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:

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

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

#nameNilClass|String|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:

  • (NilClass|String|Symbol)


72
73
74
# File 'lib/vedeu/dsl/helpers/text.rb', line 72

def name
  options[:name]
end

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

#parentNilClass|void (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:

  • (NilClass|void)


77
78
79
# File 'lib/vedeu/dsl/helpers/text.rb', line 77

def parent
  options[:parent]
end

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

#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 (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)


82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/vedeu/dsl/helpers/text.rb', line 82

def text
  if truncate?
    truncate

  elsif align?
    align

  else
    value

  end
end

#truncateString (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)


96
97
98
# File 'lib/vedeu/dsl/helpers/text.rb', line 96

def truncate
  Vedeu::DSL::Truncate.new(value, options).text
end

#truncate?Boolean|NilClass (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:



101
102
103
# File 'lib/vedeu/dsl/helpers/text.rb', line 101

def truncate?
  options[:truncate]
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: