Class: StateFu::State

Inherits:
Sprocket show all
Defined in:
lib/state.rb

Instance Attribute Summary collapse

Attributes inherited from Sprocket

#hooks, #machine, #name

Instance Method Summary collapse

Methods inherited from Sprocket

#==, #===, #add_hook, #deep_copy, #lathe, #serializable?, #to_s

Methods included from HasOptions

#[], #[]=, included

Methods included from Applicable

included

Constructor Details

#initialize(machine, name, options = {}) ⇒ State

Returns a new instance of State.



7
8
9
10
11
12
# File 'lib/state.rb', line 7

def initialize(machine, name, options={})
  @entry_requirements = [].extend ArrayWithSymbolAccessor
  @exit_requirements  = [].extend ArrayWithSymbolAccessor
  @own_events         = [].extend EventArray
  super( machine, name, options )
end

Instance Attribute Details

#entry_requirementsObject (readonly) Also known as: requirements

Returns the value of attribute entry_requirements.



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

def entry_requirements
  @entry_requirements
end

#exit_requirementsObject (readonly)

Returns the value of attribute exit_requirements.



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

def exit_requirements
  @exit_requirements
end

#own_eventsObject (readonly)

Returns the value of attribute own_events.



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

def own_events
  @own_events
end

Instance Method Details

#after?(other) ⇒ Boolean

Returns:

  • (Boolean)


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

def after?(other)
  machine.states.index(self) > machine.states.index(machine.states[other])
end

#before?(other) ⇒ Boolean

Returns:

  • (Boolean)


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

def before?(other)
  machine.states.index(self) < machine.states.index(machine.states[other])
end

#eventsObject



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

def events
  machine.events.from(self)
end

#inspectObject

display nice and short



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/state.rb', line 27

def inspect
  s = self.to_s
  s = s[0,s.length-1]
  display_hooks = hooks.dup
  display_hooks.each do |k,v|
    display_hooks.delete(k) if v.empty?
  end
  unless display_hooks.empty?
    s << " hooks=#{display_hooks.inspect}"
  end
  unless entry_requirements.empty?
    s << " entry_requirements=#{entry_requirements.inspect}"
  end
  unless exit_requirements.empty?
    s << " exit_requirements=#{exit_requirements.inspect}"
  end
  s << ">"
  s
end