Class: Vedeu::Geometry
- Inherits:
-
Object
- Object
- Vedeu::Geometry
- Defined in:
- lib/vedeu/support/geometry.rb
Instance Method Summary collapse
- #bottom ⇒ Object
- #centre ⇒ Object
- #centre_x ⇒ Object
- #centre_y ⇒ Object
- #centred ⇒ Object
- #height ⇒ Object
-
#initialize(attrs = {}) ⇒ Geometry
constructor
A new instance of Geometry.
- #left ⇒ Object
- #origin(index = 0) ⇒ Object
- #position ⇒ Object
- #right ⇒ Object
- #terminal_height ⇒ Object
- #terminal_width ⇒ Object
- #top ⇒ Object
- #width ⇒ Object
- #x ⇒ Object
- #y ⇒ Object
Constructor Details
#initialize(attrs = {}) ⇒ Geometry
Returns a new instance of Geometry.
10 11 12 |
# File 'lib/vedeu/support/geometry.rb', line 10 def initialize(attrs = {}) @attrs = attrs end |
Instance Method Details
#bottom ⇒ Object
74 75 76 |
# File 'lib/vedeu/support/geometry.rb', line 74 def bottom top + height end |
#centre ⇒ Object
46 47 48 |
# File 'lib/vedeu/support/geometry.rb', line 46 def centre [(terminal_height / 2), (terminal_width / 2)] end |
#centre_x ⇒ Object
54 55 56 |
# File 'lib/vedeu/support/geometry.rb', line 54 def centre_x centre.last end |
#centre_y ⇒ Object
50 51 52 |
# File 'lib/vedeu/support/geometry.rb', line 50 def centre_y centre.first end |
#centred ⇒ Object
42 43 44 |
# File 'lib/vedeu/support/geometry.rb', line 42 def centred @centred ||= attrs_centred end |
#height ⇒ Object
22 23 24 |
# File 'lib/vedeu/support/geometry.rb', line 22 def height @height ||= attrs_height end |
#left ⇒ Object
66 67 68 69 70 71 72 |
# File 'lib/vedeu/support/geometry.rb', line 66 def left if centred centre_x - (width / 2) else x end end |
#origin(index = 0) ⇒ Object
14 15 16 |
# File 'lib/vedeu/support/geometry.rb', line 14 def origin(index = 0) Esc.set_position(virtual_y(index), virtual_x) end |
#position ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/vedeu/support/geometry.rb', line 82 def position { y: top, x: left, height: height, width: width, centred: centred, top: top, bottom: bottom, left: left, right: right, } end |
#right ⇒ Object
78 79 80 |
# File 'lib/vedeu/support/geometry.rb', line 78 def right left + width end |
#terminal_height ⇒ Object
18 19 20 |
# File 'lib/vedeu/support/geometry.rb', line 18 def terminal_height @terminal_height ||= attrs_terminal_height end |
#terminal_width ⇒ Object
34 35 36 |
# File 'lib/vedeu/support/geometry.rb', line 34 def terminal_width @terminal_width ||= attrs_terminal_width end |
#top ⇒ Object
58 59 60 61 62 63 64 |
# File 'lib/vedeu/support/geometry.rb', line 58 def top if centred centre_y - (height / 2) else y end end |
#width ⇒ Object
38 39 40 |
# File 'lib/vedeu/support/geometry.rb', line 38 def width @width ||= attrs_width end |
#x ⇒ Object
30 31 32 |
# File 'lib/vedeu/support/geometry.rb', line 30 def x @x ||= attrs_x end |
#y ⇒ Object
26 27 28 |
# File 'lib/vedeu/support/geometry.rb', line 26 def y @y ||= attrs_y end |