Class: Vedeu::Geometry::Position Private
- Inherits:
-
Object
- Object
- Vedeu::Geometry::Position
- Defined in:
- lib/vedeu/geometry/position.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Change coordinates into an escape sequence to set the cursor position.
Instance Attribute Summary collapse
- #x ⇒ Fixnum (also: #last) readonly private
- #y ⇒ Fixnum (also: #first) readonly private
Class Method Summary collapse
-
.[](y, x) ⇒ Object
private
Convenience constructor for Vedeu::Geometry::Position.
- .coerce(value) ⇒ Vedeu::Geometry::Position private
Instance Method Summary collapse
- #<=>(other) ⇒ Fixnum private
-
#as_indices ⇒ Array<Fixnum>
private
Converts a position into an index for the terminal.
-
#down ⇒ Vedeu::Geometry::Position
private
Increase y coordinate; moves down.
-
#eql?(other) ⇒ Boolean
(also: #==)
private
An object is equal when its values are the same.
-
#initialize(y = 1, x = 1) ⇒ Vedeu::Geometry::Position
constructor
private
Initializes a new instance of Vedeu::Geometry::Position.
-
#left ⇒ Vedeu::Geometry::Position
private
Decrease x coordinate; moves left.
-
#right ⇒ Vedeu::Geometry::Position
private
Increase x coordinate; moves right.
-
#sequence ⇒ String
private
private
Returns the escape sequence to reposition the cursors at the coordinates specified by x and y.
-
#to_a ⇒ Array<Fixnum>
private
Return a tuple containing the y and x coordinates.
- #to_position ⇒ Vedeu::Geometry::Position private
-
#to_s ⇒ String
(also: #to_str)
private
Return the escape sequence required to position the cursor at a particular point on the screen.
-
#up ⇒ Vedeu::Geometry::Position
private
Decrease y coordinate; moves up.
Constructor Details
#initialize(y = 1, x = 1) ⇒ Vedeu::Geometry::Position
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Initializes a new instance of Vedeu::Geometry::Position.
49 50 51 52 53 54 |
# File 'lib/vedeu/geometry/position.rb', line 49 def initialize(y = 1, x = 1) @y = (y.nil? || y < 1) ? 1 : y @x = (x.nil? || x < 1) ? 1 : x freeze end |
Instance Attribute Details
#x ⇒ Fixnum (readonly) Also known as: last
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
19 20 21 |
# File 'lib/vedeu/geometry/position.rb', line 19 def x @x end |
#y ⇒ Fixnum (readonly) Also known as: first
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
14 15 16 |
# File 'lib/vedeu/geometry/position.rb', line 14 def y @y end |
Class Method Details
.[](y, x) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Convenience constructor for Vedeu::Geometry::Position.
25 26 27 |
# File 'lib/vedeu/geometry/position.rb', line 25 def self.[](y, x) new(y, x) end |
.coerce(value) ⇒ Vedeu::Geometry::Position
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/vedeu/geometry/position.rb', line 31 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)) end end |
Instance Method Details
#<=>(other) ⇒ Fixnum
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
69 70 71 72 73 74 75 76 77 |
# File 'lib/vedeu/geometry/position.rb', line 69 def <=>(other) if y == other.y x <=> other.x else y <=> other.y end end |
#as_indices ⇒ Array<Fixnum>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Converts a position into an index for the terminal. An index is the position minus 1.
60 61 62 63 64 65 |
# File 'lib/vedeu/geometry/position.rb', line 60 def as_indices xi = ((x - 1) <= 1) ? 0 : (x - 1) yi = ((y - 1) <= 1) ? 0 : (y - 1) [yi, xi] end |
#down ⇒ Vedeu::Geometry::Position
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Increase y coordinate; moves down.
118 119 120 |
# File 'lib/vedeu/geometry/position.rb', line 118 def down Vedeu::Geometry::Position.new(y + 1, x) end |
#eql?(other) ⇒ Boolean Also known as: ==
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
An object is equal when its values are the same.
83 84 85 |
# File 'lib/vedeu/geometry/position.rb', line 83 def eql?(other) self.class == other.class && (x == other.x && y == other.y) end |
#left ⇒ Vedeu::Geometry::Position
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Decrease x coordinate; moves left.
125 126 127 |
# File 'lib/vedeu/geometry/position.rb', line 125 def left Vedeu::Geometry::Position.new(y, x - 1) end |
#right ⇒ Vedeu::Geometry::Position
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Increase x coordinate; moves right.
132 133 134 |
# File 'lib/vedeu/geometry/position.rb', line 132 def right Vedeu::Geometry::Position.new(y, x + 1) end |
#sequence ⇒ String (private)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns the escape sequence to reposition the cursors at the coordinates specified by x and y.
149 150 151 |
# File 'lib/vedeu/geometry/position.rb', line 149 def sequence "\e[#{y};#{x}H".freeze end |
#to_a ⇒ Array<Fixnum>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Return a tuple containing the y and x coordinates.
91 92 93 |
# File 'lib/vedeu/geometry/position.rb', line 91 def to_a [y, x] end |
#to_position ⇒ Vedeu::Geometry::Position
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
96 97 98 |
# File 'lib/vedeu/geometry/position.rb', line 96 def to_position self end |
#to_s ⇒ String Also known as: to_str
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
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.
108 109 110 111 112 |
# File 'lib/vedeu/geometry/position.rb', line 108 def to_s return "#{sequence}#{yield}".freeze if block_given? sequence end |
#up ⇒ Vedeu::Geometry::Position
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Decrease y coordinate; moves up.
139 140 141 |
# File 'lib/vedeu/geometry/position.rb', line 139 def up Vedeu::Geometry::Position.new(y - 1, x) end |