Class: Vedeu::Geometries::Position Private
- Inherits:
-
Object
- Object
- Vedeu::Geometries::Position
- 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.
- .coerce(value) ⇒ Vedeu::Geometries::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::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.
58 59 60 61 62 63 |
# File 'lib/vedeu/geometries/position.rb', line 58 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.
27 28 29 |
# File 'lib/vedeu/geometries/position.rb', line 27 def self.[](y = 1, x = 1) new(y, x) end |
.coerce(value) ⇒ 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.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/vedeu/geometries/position.rb', line 34 def self.coerce(value) if value.is_a?(self) value elsif value.is_a?(Array) new(*value) elsif value.is_a?(Fixnum) new(value, 1) elsif value.is_a?(Hash) new(value.fetch(:y, 1), value.fetch(:x, 1)) elsif value.is_a?(NilClass) nil 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.
78 79 80 81 82 83 84 85 86 |
# File 'lib/vedeu/geometries/position.rb', line 78 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.
69 70 71 72 73 74 |
# File 'lib/vedeu/geometries/position.rb', line 69 def as_indices xi = ((x - 1) <= 1) ? 0 : (x - 1) yi = ((y - 1) <= 1) ? 0 : (y - 1) [yi, xi] 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.
141 142 143 |
# File 'lib/vedeu/geometries/position.rb', line 141 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.
92 93 94 |
# File 'lib/vedeu/geometries/position.rb', line 92 def eql?(other) self.class == 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.
148 149 150 |
# File 'lib/vedeu/geometries/position.rb', line 148 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.
155 156 157 |
# File 'lib/vedeu/geometries/position.rb', line 155 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.
172 173 174 |
# File 'lib/vedeu/geometries/position.rb', line 172 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.
100 101 102 |
# File 'lib/vedeu/geometries/position.rb', line 100 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.
105 106 107 |
# File 'lib/vedeu/geometries/position.rb', line 105 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.
112 113 114 115 116 117 118 119 |
# File 'lib/vedeu/geometries/position.rb', line 112 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.
131 132 133 134 135 |
# File 'lib/vedeu/geometries/position.rb', line 131 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.
162 163 164 |
# File 'lib/vedeu/geometries/position.rb', line 162 def up Vedeu::Geometries::Position.new(y - 1, x) end |