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

Methods included from 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 = '', 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

#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

#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

#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

#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

#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