Class: Vedeu::Geometries::Position Private
- Inherits:
-
Object
- Object
- Vedeu::Geometries::Position
- Extended by:
- Forwardable
- Defined in:
- lib/vedeu/geometries/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 = 1, x = 1) ⇒ Object
private
Convenience constructor for Vedeu::Geometries::Position.
Instance Method Summary collapse
- #<=>(other) ⇒ Fixnum private
-
#as_indices ⇒ Array<Fixnum>
private
Converts a position into an index for the terminal.
-
#down ⇒ Vedeu::Geometries::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::Geometries::Position
constructor
private
Initializes a new instance of Vedeu::Geometries::Position.
-
#left ⇒ Vedeu::Geometries::Position
private
Decrease x coordinate; moves left.
-
#right ⇒ Vedeu::Geometries::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_ast ⇒ String private
-
#to_h ⇒ Hash<Symbol => Fixnum|NilClass>
(also: #to_hash)
private
Return the position as a Hash.
-
#to_s(&block) ⇒ String
(also: #to_str)
private
Return the escape sequence required to position the cursor at a particular point on the screen.
-
#up ⇒ Vedeu::Geometries::Position
private
Decrease y coordinate; moves up.
Constructor Details
#initialize(y = 1, x = 1) ⇒ Vedeu::Geometries::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::Geometries::Position.
45 46 47 48 49 50 |
# File 'lib/vedeu/geometries/position.rb', line 45 def initialize(y = 1, x = 1) @y = Vedeu::Point.coerce(value: y, max: Vedeu.height).value @x = Vedeu::Point.coerce(value: x, max: Vedeu.width).value 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.
21 22 23 |
# File 'lib/vedeu/geometries/position.rb', line 21 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.
16 17 18 |
# File 'lib/vedeu/geometries/position.rb', line 16 def y @y end |
Class Method Details
.[](y = 1, x = 1) ⇒ 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::Geometries::Position.
34 35 36 |
# File 'lib/vedeu/geometries/position.rb', line 34 def [](y = 1, x = 1) new(y, x) 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.
65 66 67 68 69 70 71 72 73 |
# File 'lib/vedeu/geometries/position.rb', line 65 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.
56 57 58 59 60 61 |
# File 'lib/vedeu/geometries/position.rb', line 56 def as_indices ix = Vedeu::Point.coerce(value: (x - 1), min: 0).value iy = Vedeu::Point.coerce(value: (y - 1), min: 0).value [iy, ix] end |
#down ⇒ Vedeu::Geometries::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.
128 129 130 |
# File 'lib/vedeu/geometries/position.rb', line 128 def down Vedeu::Geometries::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.
79 80 81 |
# File 'lib/vedeu/geometries/position.rb', line 79 def eql?(other) self.class.equal?(other.class) && x == other.x && y == other.y end |
#left ⇒ Vedeu::Geometries::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.
135 136 137 |
# File 'lib/vedeu/geometries/position.rb', line 135 def left Vedeu::Geometries::Position.new(y, x - 1) end |
#right ⇒ Vedeu::Geometries::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.
142 143 144 |
# File 'lib/vedeu/geometries/position.rb', line 142 def right Vedeu::Geometries::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.
159 160 161 |
# File 'lib/vedeu/geometries/position.rb', line 159 def sequence "\e[#{y};#{x}H" 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.
87 88 89 |
# File 'lib/vedeu/geometries/position.rb', line 87 def to_a [y, x] end |
#to_ast ⇒ String
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.
92 93 94 |
# File 'lib/vedeu/geometries/position.rb', line 92 def to_ast ":y#{y}_x#{x}" end |
#to_h ⇒ Hash<Symbol => Fixnum|NilClass> Also known as: to_hash
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 position as a Hash.
99 100 101 102 103 104 105 106 |
# File 'lib/vedeu/geometries/position.rb', line 99 def to_h { position: { y: y, x: x, }, } end |
#to_s(&block) ⇒ 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.
118 119 120 121 122 |
# File 'lib/vedeu/geometries/position.rb', line 118 def to_s(&block) return "#{sequence}#{yield}" if block_given? sequence end |
#up ⇒ Vedeu::Geometries::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.
149 150 151 |
# File 'lib/vedeu/geometries/position.rb', line 149 def up Vedeu::Geometries::Position.new(y - 1, x) end |