Class: Vedeu::Geometry::Area
- Inherits:
-
Object
- Object
- Vedeu::Geometry::Area
- Defined in:
- lib/vedeu/geometry/area.rb
Overview
Define an area from dimensions or points.
Instance Attribute Summary collapse
-
#x ⇒ Fixnum
(also: #left)
readonly
Returns the left coordinate (column/character start position) of the interface.
-
#xn ⇒ Fixnum
(also: #right)
readonly
Returns the right coordinate (column/ character end position) of the interface.
-
#y ⇒ Fixnum
(also: #top)
readonly
Returns the top coordinate (row/line start position) of the interface.
-
#yn ⇒ Fixnum
(also: #bottom)
readonly
Returns the bottom coordinate (row/line end position) of the interface.
Class Method Summary collapse
Instance Method Summary collapse
-
#centre ⇒ Array<Fixnum>
Returns an array containing the centred y and x coordinates of the interface.
-
#centre_x ⇒ Fixnum
Returns the centred x coordinate (the horizontal centre character) of the interface.
-
#centre_y ⇒ Fixnum
Returns the centred y coordinate (the vertical centre row) of the interface.
-
#east(offset = 1) ⇒ Fixnum
Returns the column after right by default.
-
#eql?(other) ⇒ Boolean
(also: #==)
An object is equal when its values are the same.
-
#height ⇒ Fixnum
Returns the height of the interface.
-
#initialize(y:, yn:, x:, xn:) ⇒ Vedeu::Geometry::Area
constructor
Returns a new instance of Vedeu::Area.
-
#north(offset = 1) ⇒ Fixnum
Returns the row above the top by default.
-
#south(offset = 1) ⇒ Fixnum
Returns the row below the bottom by default.
-
#west(offset = 1) ⇒ Fixnum
Returns the column before left by default.
-
#width ⇒ Fixnum
Returns the width of the interface.
Constructor Details
#initialize(y:, yn:, x:, xn:) ⇒ Vedeu::Geometry::Area
Returns a new instance of Vedeu::Area.
78 79 80 81 82 83 |
# File 'lib/vedeu/geometry/area.rb', line 78 def initialize(y:, yn:, x:, xn:) @y = y @yn = yn @x = x @xn = xn end |
Instance Attribute Details
#x ⇒ Fixnum (readonly) Also known as: left
Returns the left coordinate (column/character start position) of the interface.
24 25 26 |
# File 'lib/vedeu/geometry/area.rb', line 24 def x @x end |
#xn ⇒ Fixnum (readonly) Also known as: right
Returns the right coordinate (column/ character end position) of the interface.
30 31 32 |
# File 'lib/vedeu/geometry/area.rb', line 30 def xn @xn end |
#y ⇒ Fixnum (readonly) Also known as: top
Returns the top coordinate (row/line start position) of the interface.
12 13 14 |
# File 'lib/vedeu/geometry/area.rb', line 12 def y @y end |
#yn ⇒ Fixnum (readonly) Also known as: bottom
Returns the bottom coordinate (row/line end position) of the interface.
18 19 20 |
# File 'lib/vedeu/geometry/area.rb', line 18 def yn @yn end |
Class Method Details
.from_attributes(attributes = {}) ⇒ Vedeu::Geometry::Area
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/vedeu/geometry/area.rb', line 46 def self.from_attributes(attributes = {}) y_attributes = { d: attributes[:y], dn: attributes[:yn], d_dn: attributes[:y_yn], default: Vedeu.height, maximised: attributes[:maximised], centred: attributes[:centred], # alignment: attributes[:alignment], } x_attributes = { d: attributes[:x], dn: attributes[:xn], d_dn: attributes[:x_xn], default: Vedeu.width, maximised: attributes[:maximised], centred: attributes[:centred], alignment: attributes[:alignment], } y_yn = Vedeu::Geometry::Dimension.pair(y_attributes) x_xn = Vedeu::Geometry::Dimension.pair(x_attributes) new(y: y_yn[0], yn: y_yn[-1], x: x_xn[0], xn: x_xn[-1]) end |
Instance Method Details
#centre ⇒ Array<Fixnum>
Returns an array containing the centred y and x coordinates of the interface.
99 100 101 |
# File 'lib/vedeu/geometry/area.rb', line 99 def centre [centre_y, centre_x] end |
#centre_x ⇒ Fixnum
Returns the centred x coordinate (the horizontal centre character) of the interface.
115 116 117 |
# File 'lib/vedeu/geometry/area.rb', line 115 def centre_x (width / 2) + x end |
#centre_y ⇒ Fixnum
Returns the centred y coordinate (the vertical centre row) of the interface.
107 108 109 |
# File 'lib/vedeu/geometry/area.rb', line 107 def centre_y (height / 2) + y end |
#east(offset = 1) ⇒ Fixnum
Returns the column after right by default.
159 160 161 |
# File 'lib/vedeu/geometry/area.rb', line 159 def east(offset = 1) xn + offset end |
#eql?(other) ⇒ Boolean Also known as: ==
An object is equal when its values are the same.
89 90 91 92 |
# File 'lib/vedeu/geometry/area.rb', line 89 def eql?(other) self.class == other.class && y == other.y && yn == other.yn && x == other.x && xn == other.xn end |
#height ⇒ Fixnum
Returns the height of the interface.
122 123 124 |
# File 'lib/vedeu/geometry/area.rb', line 122 def height (y..yn).size end |
#north(offset = 1) ⇒ Fixnum
Returns the row above the top by default.
144 145 146 |
# File 'lib/vedeu/geometry/area.rb', line 144 def north(offset = 1) y - offset end |
#south(offset = 1) ⇒ Fixnum
Returns the row below the bottom by default.
174 175 176 |
# File 'lib/vedeu/geometry/area.rb', line 174 def south(offset = 1) yn + offset end |
#west(offset = 1) ⇒ Fixnum
Returns the column before left by default.
189 190 191 |
# File 'lib/vedeu/geometry/area.rb', line 189 def west(offset = 1) x - offset end |
#width ⇒ Fixnum
Returns the width of the interface.
129 130 131 |
# File 'lib/vedeu/geometry/area.rb', line 129 def width (x..xn).size end |