Class: TerminalNotes::Cursor

Inherits:
Object
  • Object
show all
Defined in:
lib/terminal-notes/cursor.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#xObject (readonly)

Returns the value of attribute x.



3
4
5
# File 'lib/terminal-notes/cursor.rb', line 3

def x
  @x
end

#yObject (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_hashObject



22
23
24
# File 'lib/terminal-notes/cursor.rb', line 22

def to_hash
    { x: @x, y: @y }
end