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.



1520
1521
1522
1523
1524
1525
# File 'lib/mxrb/dsl/builder.rb', line 1520

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

Instance Method Details

#on(value, &block) ⇒ Object



1527
1528
1529
1530
1531
1532
1533
1534
1535
# File 'lib/mxrb/dsl/builder.rb', line 1527

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



1537
1538
1539
1540
1541
# File 'lib/mxrb/dsl/builder.rb', line 1537

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