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.



18
19
20
21
22
23
# File 'lib/cpee/statemachine.rb', line 18

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)


34
35
36
# File 'lib/cpee/statemachine.rb', line 34

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

#readonly?(id) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#setable?(id, nval) ⇒ Boolean

Returns:

  • (Boolean)


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

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