class StateMachineChecker::CTL::Atom
An atomic proposition about a single object.
Attributes
fn[R]
name[R]
Public Class Methods
new(method_name_or_fn)
click to toggle source
@param [Symbol, Proc] method_name_or_fn
@example
Atom.new(:shipped?) Atom.new(->(x) { x.shipped? })
# 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
Public Instance Methods
apply(instance)
click to toggle source
Evaluate the atom on the given instance.
@example
even_atom = Atom.new(:even?) even_atom.apply(6) #=> true even_atom.apply(7) #=> false
# File lib/state_machine_checker/ctl/atom.rb, line 29 def apply(instance) fn.call(instance) end
atoms()
click to toggle source
Returns an enumerator containing only this object, as it is an atom.
@return [Enumerator<Atom>]
# File lib/state_machine_checker/ctl/atom.rb, line 36 def atoms [self] end
check(machine)
click to toggle source
Check which states of the machine are labeled with this atom.
@param [LabeledMachine] machine @return [CheckResult]
# 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()
click to toggle source
# File lib/state_machine_checker/ctl/atom.rb, line 53 def to_s name end