Class: Cauldron::VarCollectOperator

Inherits:
Object
  • Object
show all
Defined in:
lib/cauldron/operator/var_collect_operator.rb

Instance Method Summary collapse

Constructor Details

#initialize(indexes) ⇒ VarCollectOperator

Returns a new instance of VarCollectOperator.



5
6
7
# File 'lib/cauldron/operator/var_collect_operator.rb', line 5

def initialize(indexes)
  @indexes = indexes
end

Instance Method Details

#build(children, scope) ⇒ Object



23
24
25
# File 'lib/cauldron/operator/var_collect_operator.rb', line 23

def build(children, scope)
  to_sexp(scope, children)
end

#to_ruby(contents, variables) ⇒ Object



9
10
11
# File 'lib/cauldron/operator/var_collect_operator.rb', line 9

def to_ruby(contents, variables)
  Sorcerer.source self.to_sexp( contents ,variables)
end

#to_sexp(scope, operators) ⇒ Object



13
14
15
16
17
18
19
20
21
# File 'lib/cauldron/operator/var_collect_operator.rb', line 13

def to_sexp(scope, operators)
  scope_var = scope.new_variable!
  second_scope_var = scope.new_variable!
  if operators.empty?
    return [:stmts_add, [:stmts_new], [:assign, [:var_field, [:@ident, scope_var ]], [:method_add_block, [:call, [:vcall, [:@ident, scope[@indexes[0]]]], :".", [:@ident, "collect"]], [:do_block, [:block_var, [:params, [[:@ident, second_scope_var]], nil, nil, nil, nil, nil, nil], false], [:stmts_add, [:stmts_new], [:var_ref, [:@ident, second_scope_var]]]]]]]
  else
    return [:stmts_add, [:stmts_new], [:assign, [:var_field, [:@ident, scope_var ]], [:method_add_block, [:call, [:vcall, [:@ident, scope[@indexes[0]]]], :".", [:@ident, "collect"]], [:do_block, [:block_var, [:params, [[:@ident, second_scope_var]], nil, nil, nil, nil, nil, nil], false], [:stmts_add, [:stmts_new], operators.first.content.build([], scope) ]]]]]
  end
end