Class: Vedeu::DSL::Align Private
- Inherits:
-
Object
- Object
- Vedeu::DSL::Align
- Extended by:
- Forwardable
- Includes:
- Common
- Defined in:
- lib/vedeu/dsl/helpers/align.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.
Aligns a text value based on given options when building views.
Instance Attribute Summary collapse
- #options ⇒ Hash readonly protected private
- #value ⇒ String readonly protected private
Instance Method Summary collapse
- #alignment ⇒ Vedeu::Coercers::Alignment private private
-
#centre ⇒ String
(also: #center)
private
private
The value padded to width, centralized.
-
#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::Align constructor private
-
#left ⇒ String
private
private
The value padded to width, left justified.
-
#right ⇒ String
private
private
The value padded to width, right justified.
- #text ⇒ String private
-
#width ⇒ Fixnum
private
private
Return the width given in the options.
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::Align
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.
29 30 31 32 |
# File 'lib/vedeu/dsl/helpers/align.rb', line 29 def initialize(value = '', = {}) @value = value || '' @options = defaults.merge!() end |
Instance Attribute Details
#options ⇒ Hash (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.
58 59 60 |
# File 'lib/vedeu/dsl/helpers/align.rb', line 58 def @options end |
#value ⇒ 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.
62 63 64 |
# File 'lib/vedeu/dsl/helpers/align.rb', line 62 def value @value end |
Instance Method Details
#alignment ⇒ 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.
67 68 69 |
# File 'lib/vedeu/dsl/helpers/align.rb', line 67 def alignment @_alignment ||= Vedeu::Coercers::Alignment.coerce([:align]) end |
#centre ⇒ String (private) Also known as: center
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 value padded to width, centralized.
74 75 76 |
# File 'lib/vedeu/dsl/helpers/align.rb', line 74 def centre value.center(width, [:pad]) end |
#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.
80 81 82 83 84 85 86 87 |
# File 'lib/vedeu/dsl/helpers/align.rb', line 80 def defaults { align: :left, name: nil, pad: ' ', 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.
90 91 92 |
# File 'lib/vedeu/dsl/helpers/align.rb', line 90 def geometry @_geometry ||= Vedeu.geometries.by_name([:name]) end |
#left ⇒ 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.
The value padded to width, left justified. See #width.
97 98 99 |
# File 'lib/vedeu/dsl/helpers/align.rb', line 97 def left value.ljust(width, [:pad]) end |
#right ⇒ 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.
The value padded to width, right justified.
104 105 106 |
# File 'lib/vedeu/dsl/helpers/align.rb', line 104 def right value.rjust(width, [:pad]) 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.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/vedeu/dsl/helpers/align.rb', line 35 def text if unaligned? value elsif left_aligned? left elsif centre_aligned? centre elsif right_aligned? right else value 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 given in the options. If no :width option was set, but a :name option was set, then we can use the width of the interface to determine the correct width to use. There is a caveat in this; if the :align option was set to :left, but no :width provided, then we don’t want to use the interface’s width. The reason being, is that there may be another stream in this line which will not appear by default as it will be push right out of the visible area.
Return the width of the interface when a name is given, otherwise use the given width.
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/vedeu/dsl/helpers/align.rb', line 121 def width if present?([:width]) [:width] elsif present?([:name]) if left_aligned? value.size else geometry.bordered_width end else value.size end end |