Class: Mxrb::Dsl::DecisionBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/mxrb/dsl/builder.rb

Instance Method Summary collapse

Constructor Details

#initialize(condition) ⇒ DecisionBuilder

Returns a new instance of DecisionBuilder.



1652
1653
1654
1655
1656
1657
# File 'lib/mxrb/dsl/builder.rb', line 1652

def initialize(condition)
  @condition      = condition
  @true_branch    = []
  @false_branch   = []
  @branches       = {}
end

Instance Method Details

#on(value, &block) ⇒ Object



1659
1660
1661
1662
1663
1664
1665
1666
1667
# File 'lib/mxrb/dsl/builder.rb', line 1659

def on(value, &block)
  bb = BranchBuilder.new
  bb.instance_eval(&block) if block
  case value
  when true  then @true_branch  = bb.activities
  when false then @false_branch = bb.activities
  end
  @branches[value] = bb.activities
end

#to_hObject



1669
1670
1671
1672
1673
# File 'lib/mxrb/dsl/builder.rb', line 1669

def to_h
  { type: :decision, condition: @condition,
    true_branch: @true_branch, false_branch: @false_branch,
    branches: @branches }
end