Class: TTYString::Cursor

Inherits:
Object
  • Object
show all
Defined in:
lib/tty_string/cursor.rb

Overview

point on a screen. you can move it

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(row = 0, col = 0) ⇒ Cursor

Returns a new instance of Cursor.



8
9
10
11
# File 'lib/tty_string/cursor.rb', line 8

def initialize(row = 0, col = 0)
  @row = row
  @col = col
end

Instance Attribute Details

#colObject

Returns the value of attribute col.



6
7
8
# File 'lib/tty_string/cursor.rb', line 6

def col
  @col
end

#rowObject

Returns the value of attribute row.



6
7
8
# File 'lib/tty_string/cursor.rb', line 6

def row
  @row
end

Instance Method Details

#down(count = 1) ⇒ Object

Raises:

  • (ArgumentError)


37
38
39
40
41
42
# File 'lib/tty_string/cursor.rb', line 37

def down(count = 1)
  count = count.to_i
  raise ArgumentError unless count >= 0

  self.row += count
end

#left(count = 1) ⇒ Object

Raises:

  • (ArgumentError)


23
24
25
26
27
28
# File 'lib/tty_string/cursor.rb', line 23

def left(count = 1)
  count = count.to_i
  raise ArgumentError if count.negative?

  self.col -= count
end

#right(count = 1) ⇒ Object

Raises:

  • (ArgumentError)


44
45
46
47
48
49
# File 'lib/tty_string/cursor.rb', line 44

def right(count = 1)
  count = count.to_i
  raise ArgumentError unless count >= 0

  self.col += count
end

#to_aryObject Also known as: to_a



51
52
53
# File 'lib/tty_string/cursor.rb', line 51

def to_ary
  [row, col]
end

#up(count = 1) ⇒ Object

Raises:

  • (ArgumentError)


30
31
32
33
34
35
# File 'lib/tty_string/cursor.rb', line 30

def up(count = 1)
  count = count.to_i
  raise ArgumentError if count.negative?

  self.row -= count
end