Class: SFRP::Low::DSL::IfChainProxy

Inherits:
Object
  • Object
show all
Defined in:
lib/sfrp/low/dsl.rb

Instance Method Summary collapse

Constructor Details

#initializeIfChainProxy

Returns a new instance of IfChainProxy.



97
98
99
100
101
# File 'lib/sfrp/low/dsl.rb', line 97

def initialize
  @finised = false
  @cond_exps = []
  @exps = []
end

Instance Method Details

#append_case(cond_exp, exp) ⇒ Object



109
110
111
112
113
# File 'lib/sfrp/low/dsl.rb', line 109

def append_case(cond_exp, exp)
  return if @finised
  @cond_exps << cond_exp
  @exps << exp
end

#finish(exp) ⇒ Object



103
104
105
106
107
# File 'lib/sfrp/low/dsl.rb', line 103

def finish(exp)
  return if @finished
  @exps << exp
  @finised = true
end

#to_expObject



115
116
117
118
119
120
121
122
# File 'lib/sfrp/low/dsl.rb', line 115

def to_exp
  raise if @exps.empty?
  @cond_exps.pop unless @finised
  @finised = true
  xs = @cond_exps.zip(@exps).map { |ce, e| "(#{ce}) ? (#{e}) :" }
  last = "(#{@exps[-1]})"
  (xs + [last]).join(' ')
end