Class: Laminar::Flow::Branch
- Inherits:
-
Object
- Object
- Laminar::Flow::Branch
- Includes:
- OptionsValidator
- Defined in:
- lib/laminar/flow/branch.rb
Overview
Specification for a target rule transition.
Instance Attribute Summary collapse
-
#condition ⇒ Object
The branch condition (method name symbol or Proc/lambda).
-
#condition_type ⇒ Object
Returns the value of attribute condition_type.
-
#name ⇒ Object
Target rule to branch to.
Instance Method Summary collapse
-
#initialize(name, options = {}) ⇒ Branch
constructor
A new instance of Branch.
-
#meets_condition?(target) ⇒ Boolean
True if condition is satisfied in the context.
Methods included from OptionsValidator
Constructor Details
#initialize(name, options = {}) ⇒ Branch
Returns a new instance of Branch.
20 21 22 23 24 25 26 |
# File 'lib/laminar/flow/branch.rb', line 20 def initialize(name, = {}) raise ArgumentError, 'invalid name' unless name.class.method_defined?(:to_sym) () @name = name.to_sym define_condition() end |
Instance Attribute Details
#condition ⇒ Object
Returns the branch condition (method name symbol or Proc/lambda).
18 |
# File 'lib/laminar/flow/branch.rb', line 18 attr_accessor :name, :condition, :condition_type |
#condition_type ⇒ Object
Returns the value of attribute condition_type.
18 19 20 |
# File 'lib/laminar/flow/branch.rb', line 18 def condition_type @condition_type end |
#name ⇒ Object
Returns target rule to branch to.
18 19 20 |
# File 'lib/laminar/flow/branch.rb', line 18 def name @name end |
Instance Method Details
#meets_condition?(target) ⇒ Boolean
Returns true if condition is satisfied in the context.
31 32 33 34 35 36 |
# File 'lib/laminar/flow/branch.rb', line 31 def meets_condition?(target) return true if condition.nil? result = run_condition(target) condition_type == :if ? result : !result end |