Class: SFRP::Low::DSL::IfChainProxy
- Inherits:
-
Object
- Object
- SFRP::Low::DSL::IfChainProxy
- Defined in:
- lib/sfrp/low/dsl.rb
Instance Method Summary collapse
- #append_case(cond_exp, exp) ⇒ Object
- #finish(exp) ⇒ Object
-
#initialize ⇒ IfChainProxy
constructor
A new instance of IfChainProxy.
- #to_exp ⇒ Object
Constructor Details
#initialize ⇒ IfChainProxy
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_exp ⇒ Object
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 |