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.
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/vedeu/support/geometry.rb', line 8 def initialize(attrs = {}) @attrs = attrs @height = attrs.fetch(:height) @width = attrs.fetch(:width) @terminal_height = attrs.fetch(:terminal_height, Terminal.height) @terminal_width = attrs.fetch(:terminal_width, Terminal.width) @y = attrs.fetch(:y, 1) @x = attrs.fetch(:x, 1) @centred = attrs.fetch(:centred, true) end |
Instance Method Details
#bottom ⇒ Object
107 108 109 |
# File 'lib/vedeu/support/geometry.rb', line 107 def bottom top + height end |
#centre ⇒ Object
79 80 81 |
# File 'lib/vedeu/support/geometry.rb', line 79 def centre [(terminal_height / 2), (terminal_width / 2)] end |
#centre_x ⇒ Object
87 88 89 |
# File 'lib/vedeu/support/geometry.rb', line 87 def centre_x centre.last end |
#centre_y ⇒ Object
83 84 85 |
# File 'lib/vedeu/support/geometry.rb', line 83 def centre_y centre.first end |
#centred ⇒ Object
75 76 77 |
# File 'lib/vedeu/support/geometry.rb', line 75 def centred !!(@centred) end |
#height ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/vedeu/support/geometry.rb', line 33 def height fail_if_less_than_one(@height) fail_if_out_of_bounds('height', @height, terminal_height) @height end |
#left ⇒ Object
99 100 101 102 103 104 105 |
# File 'lib/vedeu/support/geometry.rb', line 99 def left if centred centre_x - (width / 2) else x end end |
#origin(index = 0) ⇒ Object
19 20 21 |
# File 'lib/vedeu/support/geometry.rb', line 19 def origin(index = 0) Esc.set_position(virtual_y(index), virtual_x) end |
#position ⇒ Object
115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/vedeu/support/geometry.rb', line 115 def position { y: top, x: left, height: height, width: width, centred: centred, top: top, bottom: bottom, left: left, right: right, } end |
#right ⇒ Object
111 112 113 |
# File 'lib/vedeu/support/geometry.rb', line 111 def right left + width end |
#terminal_height ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'lib/vedeu/support/geometry.rb', line 23 def terminal_height fail_if_less_than_one(@terminal_height) fail_if_out_of_bounds('terminal_height', @terminal_height, Terminal.height) @terminal_height end |
#terminal_width ⇒ Object
49 50 51 52 53 54 55 56 57 |
# File 'lib/vedeu/support/geometry.rb', line 49 def terminal_width fail_if_less_than_one(@terminal_width) fail_if_out_of_bounds('terminal_width', @terminal_width, Terminal.width) @terminal_width end |
#top ⇒ Object
91 92 93 94 95 96 97 |
# File 'lib/vedeu/support/geometry.rb', line 91 def top if centred centre_y - (height / 2) else y end end |
#width ⇒ Object
59 60 61 62 63 64 65 |
# File 'lib/vedeu/support/geometry.rb', line 59 def width fail_if_less_than_one(@width) fail_if_out_of_bounds('width', @width, terminal_width) @width end |
#x ⇒ Object
67 68 69 70 71 72 73 |
# File 'lib/vedeu/support/geometry.rb', line 67 def x fail_if_less_than_one(@x) fail_if_out_of_bounds('x', @x, terminal_width) @x end |
#y ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/vedeu/support/geometry.rb', line 41 def y fail_if_less_than_one(@y) fail_if_out_of_bounds('y', @y, terminal_height) @y end |