Class: Vedeu::DSL::Truncate Private

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

Truncates a string to an optional width, or uses the named geometry width.

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

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::DSL::Truncate.

Parameters:

  • value (String) (defaults to: '')
  • options (Hash<Symbol => Boolean|Fixnum|NilClass|String| Symbol]) (defaults to: {})

    ptions [Hash<Symbol => Boolean|Fixnum|NilClass|String| Symbol]

Options Hash (options):

  • name (String|Symbol)

    The name of the geometry to use to determine the width if the width option is not given.

  • truncate (Boolean)

    Whether to truncate the value.

  • width (Fixnum)

    The width of the new value.



28
29
30
31
# File 'lib/vedeu/dsl/helpers/truncate.rb', line 28

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

Instance Attribute Details

#optionsHash<Symbol => Boolean|Fixnum|NilClass|String| Symbol] (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 => Boolean|Fixnum|NilClass|String| Symbol].

Returns:

  • (Hash<Symbol => Boolean|Fixnum|NilClass|String| Symbol])

    Hash<Symbol => Boolean|Fixnum|NilClass|String| Symbol]



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

def options
  @options
end

Instance Method Details

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

The default options/attributes for a new instance of this class.

Returns:

  • (Hash<Symbol => void>)


54
55
56
57
58
59
60
# File 'lib/vedeu/dsl/helpers/truncate.rb', line 54

def defaults
  {
    name:     nil,
    truncate: false,
    width:    nil,
  }
end

#geometryVedeu::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 the named geometry from the geometries repository.



63
64
65
# File 'lib/vedeu/dsl/helpers/truncate.rb', line 63

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

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


34
35
36
37
38
39
40
41
42
# File 'lib/vedeu/dsl/helpers/truncate.rb', line 34

def text
  if truncate?
    truncate

  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)


73
74
75
# File 'lib/vedeu/dsl/helpers/truncate.rb', line 73

def truncate
  value.slice(0, width)
end

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



68
69
70
# File 'lib/vedeu/dsl/helpers/truncate.rb', line 68

def truncate?
  truthy?(options[:truncate]) && value.size > width
end

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


78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/vedeu/dsl/helpers/truncate.rb', line 78

def value
  if present?(@value) && string?(@value)
    @value

  elsif present?(@value)
    @value.to_s

  else
    ''

  end
end

#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 of the interface when a name is given, otherwise use the given width.

Returns:

  • (Fixnum)


95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/vedeu/dsl/helpers/truncate.rb', line 95

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

  elsif present?(options[:name])
    geometry.bordered_width

  else
    value.size

  end
end