Class: Optimus::Transformers::ColumnCalculator::ComputedColumn

Inherits:
Object
  • Object
show all
Defined in:
lib/transformers/column_calculator.rb

Constant Summary collapse

COUNTERS =
{
  :next => lambda {|val|
    return val.succ if val.respond_to? :succ
    return val + 1
  }
}

Instance Method Summary collapse

Constructor Details

#initialize(name, reset_exp, options = {}) ⇒ ComputedColumn

Returns a new instance of ComputedColumn.



125
126
127
128
129
130
131
132
# File 'lib/transformers/column_calculator.rb', line 125

def initialize(name, reset_exp, options = {})
  @name = name
  @reset_exp = reset_exp
  @reset_when = options[:reset_when]
  @count_when = options[:count_when]
  @count_by = options[:count_by]
  @current_value = nil
end

Instance Method Details

#evaluate(*args) ⇒ Object



134
135
136
137
138
139
140
141
142
# File 'lib/transformers/column_calculator.rb', line 134

def evaluate(*args)
  should_reset = @reset_when.bool_eval(*args)
  if should_reset
    @current_value = @reset_exp.evaluate(*args)
  end
  should_count = @count_when.bool_eval(*args)
  next_val! if should_count
  @current_value
end