Class: Moon::Tabular::Cursor

Inherits:
Object
  • Object
show all
Defined in:
lib/moon/packages/data_bags/tabular/cursor.rb

Overview

A Cursor is used to navigate a Table without having to specify the data position each time.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(src) ⇒ Cursor

Returns a new instance of Cursor.

Parameters:


12
13
14
15
# File 'lib/moon/packages/data_bags/tabular/cursor.rb', line 12

def initialize(src)
  @position = Vector2.zero
  @src = src
end

Instance Attribute Details

#positionMoon::Vector2

Returns:


9
10
11
# File 'lib/moon/packages/data_bags/tabular/cursor.rb', line 9

def position
  @position
end

#srcMoon::Tabular (readonly)

Returns:


7
8
9
# File 'lib/moon/packages/data_bags/tabular/cursor.rb', line 7

def src
  @src
end

Instance Method Details

#getInteger #get(x, y) ⇒ Integer Also known as: []

Retrieve value at current position

Overloads:

Returns:


23
24
25
26
27
28
29
30
# File 'lib/moon/packages/data_bags/tabular/cursor.rb', line 23

def get(*args)
  if args.size > 0
    x, y = *args
    src[position.x + x, position.y + y]
  else
    src[position.x, position.y]
  end
end

#put(value) ⇒ Object #put(x, y, value) ⇒ Object Also known as: []=

Set value at current position

Overloads:


40
41
42
43
44
45
46
47
48
49
50
# File 'lib/moon/packages/data_bags/tabular/cursor.rb', line 40

def put(*args)
  case args.size  # value

  when 1
    src[position.x, position.y] = args.first  # x, y, value

  when 3
    x, y, value = *args
    src[position.x + x, position.y + y] = value
  end
end