Class: Vedeu::Geometries::Dimension Private
- Inherits:
-
Object
- Object
- Vedeu::Geometries::Dimension
- Extended by:
- Forwardable
- Defined in:
- lib/vedeu/geometries/area/dimension.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.
A Dimension is either the height or width of an entity.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#d ⇒ Fixnum|NilClass
readonly
protected
private
The starting value (y or x).
-
#d_dn ⇒ Fixnum|NilClass
readonly
protected
private
A width or a height.
-
#default ⇒ Fixnum|NilClass
readonly
protected
private
The terminal width or height.
-
#dn ⇒ Fixnum|NilClass
readonly
protected
private
The ending value (yn or xn).
- #maximised ⇒ Boolean (also: #maximised?) readonly protected private
Class Method Summary collapse
Instance Method Summary collapse
-
#_d ⇒ Fixnum
private
private
Fetch the starting coordinate, or use 1 when not set.
-
#_dn ⇒ Fixnum
private
private
Fetch the ending coordinate.
- #alignment ⇒ Vedeu::Coercers::Alignment private private
-
#centred_d ⇒ Fixnum
private
private
Ascertains the centred starting coordinate.
-
#centred_dn ⇒ Fixnum
private
private
Ascertains the centred ending coordinate.
-
#defaults ⇒ Hash<Symbol => void>
private
private
The default options/attributes for a new instance of this class.
-
#end_coordinate ⇒ Fixnum
private
private
Ascertains the ending coordinate for a left or top aligned interface/view.
-
#initialize(attributes = {}) ⇒ Vedeu::Geometries::Dimension
constructor
private
Returns a new instance of Vedeu::Geometries::Dimension.
-
#length ⇒ Fixnum|NilClass
private
private
Provide the number of rows/lines or columns/characters.
-
#pair ⇒ Array<Fixnum>
private
Return the coordinate pair.
-
#start_coordinate ⇒ Fixnum
private
private
Ascertains the starting coordinate for a right or bottom aligned interface/view.
Constructor Details
#initialize(attributes = {}) ⇒ Vedeu::Geometries::Dimension
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::Geometries::Dimension.
43 44 45 46 47 |
# File 'lib/vedeu/geometries/area/dimension.rb', line 43 def initialize(attributes = {}) defaults.merge!(attributes).each do |key, value| instance_variable_set("@#{key}", value) end end |
Instance Attribute Details
#d ⇒ Fixnum|NilClass (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 The starting value (y or x).
79 80 81 |
# File 'lib/vedeu/geometries/area/dimension.rb', line 79 def d @d end |
#d_dn ⇒ Fixnum|NilClass (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 A width or a height.
87 88 89 |
# File 'lib/vedeu/geometries/area/dimension.rb', line 87 def d_dn @d_dn end |
#default ⇒ Fixnum|NilClass (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 The terminal width or height.
91 92 93 |
# File 'lib/vedeu/geometries/area/dimension.rb', line 91 def default @default end |
#dn ⇒ Fixnum|NilClass (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 The ending value (yn or xn).
83 84 85 |
# File 'lib/vedeu/geometries/area/dimension.rb', line 83 def dn @dn end |
#maximised ⇒ Boolean (readonly, protected) Also known as: maximised?
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.
95 96 97 |
# File 'lib/vedeu/geometries/area/dimension.rb', line 95 def maximised @maximised end |
Class Method Details
.pair(attributes = {}) ⇒ Array<Fixnum>
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.
26 27 28 |
# File 'lib/vedeu/geometries/area/dimension.rb', line 26 def self.pair(attributes = {}) new(attributes).pair end |
Instance Method Details
#_d ⇒ 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.
Fetch the starting coordinate, or use 1 when not set.
196 197 198 |
# File 'lib/vedeu/geometries/area/dimension.rb', line 196 def _d d || 1 end |
#_dn ⇒ 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.
Fetch the ending coordinate.
1) if an end value was given, use that. 2) if a start value wasn’t given, but a width or height was,
use the width or height.
3) if a start value was given and a width or height was given,
add the width or height to the start and minus 1.
4) otherwise, use the terminal default width or height.
210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 |
# File 'lib/vedeu/geometries/area/dimension.rb', line 210 def _dn if dn dn elsif d.nil? && d_dn d_dn elsif d && d_dn (d + d_dn) - 1 elsif default default else 1 end end |
#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.
101 102 103 |
# File 'lib/vedeu/geometries/area/dimension.rb', line 101 def alignment @_alignment ||= Vedeu::Coercers::Alignment.coerce(@alignment) end |
#centred_d ⇒ 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.
Ascertains the centred starting coordinate.
133 134 135 136 |
# File 'lib/vedeu/geometries/area/dimension.rb', line 133 def centred_d d = (default / 2) - (length / 2) d < 1 ? 1 : d end |
#centred_dn ⇒ 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.
Ascertains the centred ending coordinate.
146 147 148 149 |
# File 'lib/vedeu/geometries/area/dimension.rb', line 146 def centred_dn dn = (default / 2) + (length / 2) dn > default ? default : dn 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.
230 231 232 233 234 235 236 237 238 |
# File 'lib/vedeu/geometries/area/dimension.rb', line 230 def defaults { alignment: :none, d: nil, dn: nil, d_dn: nil, maximised: false, } end |
#end_coordinate ⇒ 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.
Ascertains the ending coordinate for a left or top aligned interface/view.
1) Use the width or height (d_dn), or 2) Use the xn or yn (dn), or 3) Default to the terminal width or height.
159 160 161 162 163 164 165 166 167 168 169 170 |
# File 'lib/vedeu/geometries/area/dimension.rb', line 159 def end_coordinate if d_dn (d_dn > default) ? default : d_dn elsif dn dn else default end end |
#length ⇒ Fixnum|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.
Provide the number of rows/lines or columns/characters.
1) Use the starting (x or y) and ending (xn or yn) values. 2) Or use the width or height value. 3) Or use the default/current terminal width or height value.
112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/vedeu/geometries/area/dimension.rb', line 112 def length if d && dn (dn - d) + 1 elsif d_dn d_dn else default end end |
#pair ⇒ Array<Fixnum>
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 coordinate pair.
1) If maximised, it will be from the first row/line or column/
character to the last row/line or column/character of the
terminal.
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/vedeu/geometries/area/dimension.rb', line 56 def pair if maximised? [1, default] elsif bottom_aligned? || right_aligned? [start_coordinate, default] elsif centre_aligned? || middle_aligned? [centred_d, centred_dn] elsif left_aligned? || top_aligned? [1, end_coordinate] else [_d, _dn] end end |
#start_coordinate ⇒ 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.
Ascertains the starting coordinate for a right or bottom aligned interface/view.
1) Use the width or height (d_dn), or 2) Use the x or y (d), or 3) Default to 1.
180 181 182 183 184 185 186 187 188 189 190 191 |
# File 'lib/vedeu/geometries/area/dimension.rb', line 180 def start_coordinate if d_dn (default - d_dn) < 1 ? 1 : (default - d_dn) elsif d d else 1 end end |