Class: CPEE::StateMachine

Inherits:
Object
  • Object
show all
Defined in:
lib/cpee/statemachine.rb

Instance Method Summary collapse

Constructor Details

#initialize(file, &state) ⇒ StateMachine

Returns a new instance of StateMachine.



24
25
26
27
28
29
# File 'lib/cpee/statemachine.rb', line 24

def initialize(file,&state)
  @states = XML::Smart.open_unprotected(file)
  @state = state
  @readonly = @states.find("/states/observable/*[*]").map { |e| e.qname.name }
  @final = @states.find("/states/observable/*[not(*)]").map { |e| e.qname.name }
end

Instance Method Details

#final?(id) ⇒ Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/cpee/statemachine.rb', line 40

def final?(id)
  @final.include? @state.call(id)
end

#readonly?(id) ⇒ Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/cpee/statemachine.rb', line 36

def readonly?(id)
  @readonly.include? @state.call(id)
end

#setable?(id, nval) ⇒ Boolean

Returns:

  • (Boolean)


31
32
33
34
# File 'lib/cpee/statemachine.rb', line 31

def setable?(id,nval)
  cval = @state.call(id)
  @states.find("/states/setable/#{cval}[#{nval}]").length > 0
end