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

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

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

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

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

Returns:

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

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



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

def defaults
  {
    name:     nil,
    truncate: false,
    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:

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



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

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:

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

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


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)


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

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:



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

def truncate?
  truthy?(options[:truncate]) && value.size > width
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:

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


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

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

  elsif present?(@value)
    @value.to_s

  else
    ''

  end
end

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

Returns:

  • (Fixnum)


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

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

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

  else
    value.size

  end
end