Class: StateMachineChecker::CTL::Atom
- Defined in:
- lib/state_machine_checker/ctl/atom.rb
Overview
An atomic proposition about a single object.
Instance Method Summary collapse
-
#apply(instance) ⇒ Object
Evaluate the atom on the given instance.
-
#atoms ⇒ Enumerator<Atom>
Returns an enumerator containing only this object, as it is an atom.
-
#check(machine) ⇒ CheckResult
Check which states of the machine are labeled with this atom.
-
#initialize(method_name_or_fn) ⇒ Atom
constructor
A new instance of Atom.
- #to_s ⇒ Object
Methods inherited from Formula
Constructor Details
#initialize(method_name_or_fn) ⇒ Atom
Returns a new instance of Atom.
14 15 16 17 18 19 20 21 |
# File 'lib/state_machine_checker/ctl/atom.rb', line 14 def initialize(method_name_or_fn) @name, @fn = if method_name_or_fn.respond_to?(:call) ["atom##{object_id}", method_name_or_fn] else # Create a function which will send the given method name. [method_name_or_fn.to_s, method_name_or_fn.to_proc] end end |
Instance Method Details
#apply(instance) ⇒ Object
Evaluate the atom on the given instance.
29 30 31 |
# File 'lib/state_machine_checker/ctl/atom.rb', line 29 def apply(instance) fn.call(instance) end |
#atoms ⇒ Enumerator<Atom>
Returns an enumerator containing only this object, as it is an atom.
36 37 38 |
# File 'lib/state_machine_checker/ctl/atom.rb', line 36 def atoms [self] end |
#check(machine) ⇒ CheckResult
Check which states of the machine are labeled with this atom.
44 45 46 47 48 49 50 51 |
# File 'lib/state_machine_checker/ctl/atom.rb', line 44 def check(machine) result = machine.states.each_with_object({}) { |state, h| satisfied = machine.labels_for_state(state).include?(self) h[state] = StateResult.new(satisfied, []) } CheckResult.new(result) end |
#to_s ⇒ Object
53 54 55 |
# File 'lib/state_machine_checker/ctl/atom.rb', line 53 def to_s name end |