Class: TerminalNotes::Cursor
- Inherits:
-
Object
- Object
- TerminalNotes::Cursor
- Defined in:
- lib/terminal-notes/cursor.rb
Instance Attribute Summary collapse
-
#x ⇒ Object
readonly
Returns the value of attribute x.
-
#y ⇒ Object
readonly
Returns the value of attribute y.
Instance Method Summary collapse
-
#initialize(x: 0, y: 0) ⇒ Cursor
constructor
A new instance of Cursor.
- #moveBy(deltaX = 0, deltaY = 0) ⇒ Object
- #moveTo(x: nil, y: nil) ⇒ Object
- #to_hash ⇒ Object
Constructor Details
#initialize(x: 0, y: 0) ⇒ Cursor
Returns a new instance of Cursor.
5 6 7 8 |
# File 'lib/terminal-notes/cursor.rb', line 5 def initialize(x: 0, y: 0) @x = x.to_i @y = y.to_i end |
Instance Attribute Details
#x ⇒ Object (readonly)
Returns the value of attribute x.
3 4 5 |
# File 'lib/terminal-notes/cursor.rb', line 3 def x @x end |
#y ⇒ Object (readonly)
Returns the value of attribute y.
3 4 5 |
# File 'lib/terminal-notes/cursor.rb', line 3 def y @y end |
Instance Method Details
#moveBy(deltaX = 0, deltaY = 0) ⇒ Object
10 11 12 13 14 |
# File 'lib/terminal-notes/cursor.rb', line 10 def moveBy(deltaX = 0, deltaY = 0) @x += deltaX @y += deltaY self end |
#moveTo(x: nil, y: nil) ⇒ Object
16 17 18 19 20 |
# File 'lib/terminal-notes/cursor.rb', line 16 def moveTo(x: nil, y: nil) @x = x unless x.nil? @y = y unless y.nil? self end |
#to_hash ⇒ Object
22 23 24 |
# File 'lib/terminal-notes/cursor.rb', line 22 def to_hash { x: @x, y: @y } end |