Class: Vedeu::Position
- Inherits:
-
Object
- Object
- Vedeu::Position
- Defined in:
- lib/vedeu/geometry/position.rb
Overview
Change coordinates into an escape sequence to set the cursor position.
Instance Attribute Summary collapse
-
#x ⇒ Object
(also: #last)
readonly
Returns the value of attribute x.
-
#y ⇒ Object
(also: #first)
readonly
Returns the value of attribute y.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Boolean
- #eql?(other) ⇒ Boolean
-
#initialize(y = 1, x = 1) ⇒ Position
constructor
Initializes a new instance of Position.
-
#sequence ⇒ String
private
Returns the escape sequence to reposition the cursors at the coordinates specified by x and y.
-
#to_s(&block) ⇒ String
Return the escape sequence required to position the cursor at a particular point on the screen.
Constructor Details
#initialize(y = 1, x = 1) ⇒ Position
Initializes a new instance of Position.
36 37 38 39 |
# File 'lib/vedeu/geometry/position.rb', line 36 def initialize(y = 1, x = 1) @y = (y.nil? || y < 1) ? 1 : y @x = (x.nil? || x < 1) ? 1 : x end |
Instance Attribute Details
#x ⇒ Object (readonly) Also known as: last
Returns the value of attribute x.
7 8 9 |
# File 'lib/vedeu/geometry/position.rb', line 7 def x @x end |
#y ⇒ Object (readonly) Also known as: first
Returns the value of attribute y.
7 8 9 |
# File 'lib/vedeu/geometry/position.rb', line 7 def y @y end |
Class Method Details
.coerce(value) ⇒ void
This method returns an undefined value.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/vedeu/geometry/position.rb', line 15 def self.coerce(value) if value.is_a?(self) value elsif value.is_a?(Array) new(*value) elsif value.is_a?(Hash) new(value.fetch(:y, 1), value.fetch(:x, 1)) else # not sure how to proceed end end |
Instance Method Details
#==(other) ⇒ Boolean
43 44 45 |
# File 'lib/vedeu/geometry/position.rb', line 43 def ==(other) eql?(other) end |
#eql?(other) ⇒ Boolean
49 50 51 |
# File 'lib/vedeu/geometry/position.rb', line 49 def eql?(other) self.class == other.class && (x == other.x && y == other.y) end |
#sequence ⇒ String (private)
Returns the escape sequence to reposition the cursors at the coordinates specified by x and y.
75 76 77 |
# File 'lib/vedeu/geometry/position.rb', line 75 def sequence ["\e[", y, ';', x, 'H'].join end |
#to_s(&block) ⇒ String
Return the escape sequence required to position the cursor at a particular point on the screen. When passed a block, will do the aforementioned, call the block and then reposition to this location.
59 60 61 62 63 64 65 66 67 |
# File 'lib/vedeu/geometry/position.rb', line 59 def to_s(&block) if block_given? [ sequence, yield, sequence ].join else sequence end end |