Class: Optimus::ParsedCalculator::ColumnReference

Inherits:
Expr
  • Object
show all
Defined in:
lib/expression_parser/expressions.rb

Constant Summary

Constants inherited from Expr

Expr::BINARY_OPERATORS

Instance Method Summary collapse

Methods inherited from Expr

#-@, #eq, #logical_and, #logical_not, #logical_or, #neq, #to_bool

Constructor Details

#initialize(name) ⇒ ColumnReference

Returns a new instance of ColumnReference.



132
133
134
# File 'lib/expression_parser/expressions.rb', line 132

def initialize(name)
  @name = name
end

Instance Method Details

#evaluate(*args) ⇒ Object



140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
# File 'lib/expression_parser/expressions.rb', line 140

def evaluate(*args)
  options = args.last || {}
  row = options[:row] || {}
  computed_columns = options[:computed_columns] || {}
  seen_columns = options[:seen_columns] || []
  if seen_columns.include?(@name)
    raise EvaluationLoopError.new(
      "Loop error - #{@name} depends on itself: [#{seen_columns.join(', ')}]"
    )
  end
  
  if !row[@name] and computed_columns.include?(@name)
    row[@name] = computed_columns[@name].evaluate(
      :row => row, 
      :computed_columns => computed_columns,
      :seen_columns => ([@name] + seen_columns)
    )
  end
  return magic_cast(row[@name])
end

#to_sObject



136
137
138
# File 'lib/expression_parser/expressions.rb', line 136

def to_s
  "{#{@name}}"
end