Class: Vedeu::Geometry::Dimension
- Inherits:
-
Object
- Object
- Vedeu::Geometry::Dimension
- Defined in:
- lib/vedeu/geometry/dimension.rb
Overview
A Dimension is either the height or width of an entity.
Instance Attribute Summary collapse
- #centred ⇒ Boolean (also: #centred?) readonly protected
- #d ⇒ Fixnum|NilClass readonly protected
- #d_dn ⇒ Fixnum|NilClass readonly protected
- #default ⇒ Fixnum|NilClass readonly protected
- #dn ⇒ Fixnum|NilClass readonly protected
- #maximised ⇒ Boolean (also: #maximised?) readonly protected
Class Method Summary collapse
Instance Method Summary collapse
-
#_d ⇒ Fixnum
private
Fetch the starting coordinate, or use 1 when not set.
-
#_dn ⇒ Fixnum
private
Fetch the ending coordinate.
-
#centred_d ⇒ Fixnum
private
Ascertains the centred starting coordinate.
-
#centred_dn ⇒ Fixnum
private
Ascertains the centred ending coordinate.
-
#d1 ⇒ Fixnum
Fetch the starting coordinate.
-
#d2 ⇒ Fixnum
Fetch the ending coordinate.
-
#defaults ⇒ Hash<Symbol => NilClass,Boolean>
private
Returns the default options/attributes for this class.
- #dimension ⇒ Array<Fixnum> private
-
#initialize(attributes = {}) ⇒ Vedeu::Geometry::Dimension
constructor
Returns a new instance of Vedeu::Geometry::Dimension.
- #length ⇒ Fixnum|NilClass private
- #length? ⇒ Boolean private
-
#pair ⇒ Array<Fixnum>
Fetch the coordinates.
Constructor Details
#initialize(attributes = {}) ⇒ Vedeu::Geometry::Dimension
Returns a new instance of Vedeu::Geometry::Dimension.
25 26 27 28 29 30 31 |
# File 'lib/vedeu/geometry/dimension.rb', line 25 def initialize(attributes = {}) @attributes = defaults.merge!(attributes) @attributes.each do |key, value| instance_variable_set("@#{key}", value) end end |
Instance Attribute Details
#centred ⇒ Boolean (readonly, protected) Also known as: centred?
79 80 81 |
# File 'lib/vedeu/geometry/dimension.rb', line 79 def centred @centred end |
#d ⇒ Fixnum|NilClass (readonly, protected)
58 59 60 |
# File 'lib/vedeu/geometry/dimension.rb', line 58 def d @d end |
#d_dn ⇒ Fixnum|NilClass (readonly, protected)
66 67 68 |
# File 'lib/vedeu/geometry/dimension.rb', line 66 def d_dn @d_dn end |
#default ⇒ Fixnum|NilClass (readonly, protected)
70 71 72 |
# File 'lib/vedeu/geometry/dimension.rb', line 70 def default @default end |
#dn ⇒ Fixnum|NilClass (readonly, protected)
62 63 64 |
# File 'lib/vedeu/geometry/dimension.rb', line 62 def dn @dn end |
#maximised ⇒ Boolean (readonly, protected) Also known as: maximised?
74 75 76 |
# File 'lib/vedeu/geometry/dimension.rb', line 74 def maximised @maximised end |
Class Method Details
.pair(attributes = {}) ⇒ Array<Fixnum>
11 12 13 |
# File 'lib/vedeu/geometry/dimension.rb', line 11 def self.pair(attributes = {}) new(attributes).pair end |
Instance Method Details
#_d ⇒ Fixnum (private)
Fetch the starting coordinate, or use 1 when not set.
134 135 136 |
# File 'lib/vedeu/geometry/dimension.rb', line 134 def _d d || 1 end |
#_dn ⇒ Fixnum (private)
Fetch the ending coordinate.
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
# File 'lib/vedeu/geometry/dimension.rb', line 141 def _dn if dn dn elsif d.nil? && d_dn d_dn elsif d && d_dn (d + d_dn) - 1 else default end end |
#centred_d ⇒ Fixnum (private)
Ascertains the centred starting coordinate.
120 121 122 |
# File 'lib/vedeu/geometry/dimension.rb', line 120 def centred_d (default / 2) - (length / 2) end |
#centred_dn ⇒ Fixnum (private)
Ascertains the centred ending coordinate.
127 128 129 |
# File 'lib/vedeu/geometry/dimension.rb', line 127 def centred_dn (default / 2) + (length / 2) end |
#d1 ⇒ Fixnum
Fetch the starting coordinate.
36 37 38 |
# File 'lib/vedeu/geometry/dimension.rb', line 36 def d1 dimension[0] < 1 ? 1 : dimension[0] end |
#d2 ⇒ Fixnum
Fetch the ending coordinate.
43 44 45 |
# File 'lib/vedeu/geometry/dimension.rb', line 43 def d2 dimension[-1] end |
#defaults ⇒ Hash<Symbol => NilClass,Boolean> (private)
Returns the default options/attributes for this class.
160 161 162 163 164 165 166 167 168 169 |
# File 'lib/vedeu/geometry/dimension.rb', line 160 def defaults { d: nil, dn: nil, d_dn: nil, default: nil, centred: false, maximised: false, } end |
#dimension ⇒ Array<Fixnum> (private)
85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/vedeu/geometry/dimension.rb', line 85 def dimension @dimension = if maximised? [1, default] elsif centred? && length? [centred_d, centred_dn] else [_d, _dn] end end |
#length ⇒ Fixnum|NilClass (private)
104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/vedeu/geometry/dimension.rb', line 104 def length if d && dn (d..dn).size elsif d_dn d_dn elsif default default end end |
#length? ⇒ Boolean (private)
99 100 101 |
# File 'lib/vedeu/geometry/dimension.rb', line 99 def length? default && length end |
#pair ⇒ Array<Fixnum>
Fetch the coordinates.
50 51 52 |
# File 'lib/vedeu/geometry/dimension.rb', line 50 def pair dimension end |