Class: Vedeu::Geometries::Position Private

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

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.

Parameters:

  • y (Fixnum) (defaults to: 1)

    The row/line position.

  • x (Fixnum) (defaults to: 1)

    The column/character 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

#xFixnum (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.

Returns:

  • (Fixnum)


21
22
23
# File 'lib/vedeu/geometries/position.rb', line 21

def x
  @x
end

#yFixnum (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.

Returns:

  • (Fixnum)


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.

Parameters:

  • y (Fixnum) (defaults to: 1)

    The row/line position.

  • x (Fixnum) (defaults to: 1)

    The column/character 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.

Parameters:

Returns:

  • (Fixnum)


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_indicesArray<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.

Returns:

  • (Array<Fixnum>)


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

#downVedeu::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.

Parameters:

Returns:



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

#leftVedeu::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

#rightVedeu::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

#sequenceString (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.

Returns:

  • (String)


159
160
161
# File 'lib/vedeu/geometries/position.rb', line 159

def sequence
  "\e[#{y};#{x}H"
end

#to_aArray<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.

Returns:

  • (Array<Fixnum>)


87
88
89
# File 'lib/vedeu/geometries/position.rb', line 87

def to_a
  [y, x]
end

#to_astString

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:

  • (String)


92
93
94
# File 'lib/vedeu/geometries/position.rb', line 92

def to_ast
  ":y#{y}_x#{x}"
end

#to_hHash<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.

Returns:

  • (Hash<Symbol => Fixnum|NilClass>)


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.

Parameters:

  • block (Proc)

Yield Returns:

  • (String)

    Returns the block wrapped in position escape sequences.

Returns:

  • (String)


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

#upVedeu::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