Class: Fir::Cursor

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(x, y) ⇒ Cursor

Returns a new instance of Cursor.



9
10
11
12
# File 'lib/fir/cursor.rb', line 9

def initialize(x, y)
  @x = x
  @y = y
end

Instance Attribute Details

#xObject (readonly)

Returns the value of attribute x.



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

def x
  @x
end

#yObject (readonly)

Returns the value of attribute y.



7
8
9
# File 'lib/fir/cursor.rb', line 7

def y
  @y
end

Class Method Details

.blankObject



14
15
16
# File 'lib/fir/cursor.rb', line 14

def self.blank
  new(0, 0)
end

Instance Method Details

#==(other) ⇒ Object



38
39
40
# File 'lib/fir/cursor.rb', line 38

def ==(other)
  other.x == x && other.y == y
end

#blank?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/fir/cursor.rb', line 42

def blank?
  x.zero? && y.zero?
end

#cloneObject



18
19
20
# File 'lib/fir/cursor.rb', line 18

def clone
  self.class.new(x, y)
end

#downObject



26
27
28
# File 'lib/fir/cursor.rb', line 26

def down
  self.class.new(x, y + 1)
end

#left(n) ⇒ Object



30
31
32
# File 'lib/fir/cursor.rb', line 30

def left(n)
  self.class.new(x - n, y)
end

#right(n) ⇒ Object



34
35
36
# File 'lib/fir/cursor.rb', line 34

def right(n)
  self.class.new(x + n, y)
end

#upObject



22
23
24
# File 'lib/fir/cursor.rb', line 22

def up
  self.class.new(x, y - 1)
end