Class: Commander

Inherits:
Object
  • Object
show all
Defined in:
lib/kame/remocon/commander.rb

Constant Summary collapse

METHODS =
[:clear, :reset, :pen_up, :pen_down, :color, :turn_left, :turn_right, :forward, :backward, :move_to]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(forward = nil) ⇒ Commander

Returns a new instance of Commander.



6
7
8
9
10
11
12
# File 'lib/kame/remocon/commander.rb', line 6

def initialize(forward = nil)
  if forward
    @forward = forward
  else
    @commands = []
  end
end

Instance Attribute Details

#commandsObject (readonly)

Returns the value of attribute commands.



2
3
4
# File 'lib/kame/remocon/commander.rb', line 2

def commands
  @commands
end

Instance Method Details

#<<(command) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/kame/remocon/commander.rb', line 14

def <<(command)
  if @forward
    @forward.method(command.first).call(*command[1..-1])
  else
    @commands << command
  end
end

#backward(dist) ⇒ Object



54
55
56
# File 'lib/kame/remocon/commander.rb', line 54

def backward(dist)
  self << [:forward, -dist]
end

#clearObject



22
23
24
# File 'lib/kame/remocon/commander.rb', line 22

def clear
  self << [:clear]
end

#color(color) ⇒ Object



46
47
48
# File 'lib/kame/remocon/commander.rb', line 46

def color(color)
  self << [:color, color]
end

#forward(dist) ⇒ Object



50
51
52
# File 'lib/kame/remocon/commander.rb', line 50

def forward(dist)
  self << [:forward, dist]
end

#move_to(x, y) ⇒ Object



58
59
60
# File 'lib/kame/remocon/commander.rb', line 58

def move_to(x, y)
  self << [:move_to, x, y]
end

#pen_downObject



38
39
40
# File 'lib/kame/remocon/commander.rb', line 38

def pen_down
  self << [:pen_down]
end

#pen_upObject



42
43
44
# File 'lib/kame/remocon/commander.rb', line 42

def pen_up
  self << [:pen_up]
end

#resetObject



26
27
28
# File 'lib/kame/remocon/commander.rb', line 26

def reset
  self << [:reset]
end

#turn_left(digree) ⇒ Object



30
31
32
# File 'lib/kame/remocon/commander.rb', line 30

def turn_left(digree)
  self << [:turn_left, digree]
end

#turn_right(digree) ⇒ Object



34
35
36
# File 'lib/kame/remocon/commander.rb', line 34

def turn_right(digree)
  self << [:turn_right, digree]
end