Class: Vedeu::DSL::Truncate Private
- Inherits:
-
Object
- Object
- Vedeu::DSL::Truncate
- 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
-
#options ⇒ Hash<Symbol => Boolean|Fixnum|NilClass|String| Symbol]
readonly
protected
private
Hash<Symbol => Boolean|Fixnum|NilClass|String| Symbol].
Instance Method Summary collapse
-
#defaults ⇒ Hash<Symbol => void>
private
private
The default options/attributes for a new instance of this class.
-
#geometry ⇒ Vedeu::Geometries::Geometry
private
private
Returns the named geometry from the geometries repository.
-
#initialize(value = '', options = {}) ⇒ Vedeu::DSL::Truncate
constructor
private
Returns a new instance of Vedeu::DSL::Truncate.
- #text ⇒ String private
- #truncate ⇒ String private private
- #truncate? ⇒ Boolean private private
- #value ⇒ String private private
-
#width ⇒ Fixnum
private
private
Return the width of the interface when a name is given, otherwise use the given width.
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.
28 29 30 31 |
# File 'lib/vedeu/dsl/helpers/truncate.rb', line 28 def initialize(value = '', = {}) @value = value || '' @options = defaults.merge!() end |
Instance Attribute Details
#options ⇒ Hash<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].
49 50 51 |
# File 'lib/vedeu/dsl/helpers/truncate.rb', line 49 def @options end |
Instance Method Details
#defaults ⇒ 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.
The default options/attributes for a new instance of this class.
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 |
#geometry ⇒ 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 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([:name]) end |
#text ⇒ String
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.
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 |
#truncate ⇒ String (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.
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.
68 69 70 |
# File 'lib/vedeu/dsl/helpers/truncate.rb', line 68 def truncate? truthy?([:truncate]) && value.size > width end |
#value ⇒ String (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.
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 |
#width ⇒ Fixnum (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.
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?([:width]) [:width] elsif present?([:name]) geometry.bordered_width else value.size end end |