Sha256: b00ca8bd75f2ecc4250967b17410ad7860e94949844b6af32044a09b2efc65b9

Contents?: true

Size: 1.01 KB

Versions: 1

Compression:

Stored size: 1.01 KB

Contents

# -*- coding: utf-8 -*-

# Mixin for the transitions with assignment action.
# 
module YPetri::Transition::Assignment
  # Transition's action (before validation).
  # 
  def action
    action_closure.( *domain_marking )
  end

  # Applies action to the codomain, honoring cocking. Returns true if the transition
  # fired, false if it wasn't cocked.
  # 
  def fire
    cocked?.tap { |x| ( uncock; fire! ) if x }
  end

  # Assigns the action closure result to the codomain, regardless of cocking.
  # 
  def fire!
    consciously "to #fire!" do
      act = note "action", is: Array( action )
      msg = "Wrong output arity of the action closure of #{self}"
      fail TypeError, msg if act.size != codomain.size
      codomain.each_with_index { |p, i|
        note "assigning action element no. #{i} to #{p}"
        p.marking = note "marking to assign", is: act.fetch( i )
      }
    end
    return nil
  end

  # A transitions are always _enabled_.
  # 
  def enabled?
    true
  end
end # class YPetri::Transition::Assignment

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
y_petri-2.1.3 lib/y_petri/transition/assignment.rb