Class: BabyBots::State

Inherits:
Object
  • Object
show all
Defined in:
lib/baby_bots/state.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(state, table = {}) ⇒ State

Returns a new instance of State.



6
7
8
9
# File 'lib/baby_bots/state.rb', line 6

def initialize(state, table={})
  @state = state
  @table = table
end

Instance Attribute Details

#stateObject (readonly)

Returns the value of attribute state.



4
5
6
# File 'lib/baby_bots/state.rb', line 4

def state
  @state
end

#tableObject (readonly)

Returns the value of attribute table.



4
5
6
# File 'lib/baby_bots/state.rb', line 4

def table
  @table
end

Instance Method Details

#add_transition(event, transition, &callback) ⇒ Object



11
12
13
# File 'lib/baby_bots/state.rb', line 11

def add_transition(event, transition, &callback)
  @table[event] = transition
end

#build(*args) ⇒ Object

the idea behind build is that you can call multiple :event :transition and the build method will parse them out and add them to state



18
19
20
# File 'lib/baby_bots/state.rb', line 18

def build(*args)
  args.map {|k,v| add_transition(k, v) }
end