Class: ExpressionProcessor::Proxy

Inherits:
BlankSlate show all
Defined in:
lib/expression_processor.rb

Instance Method Summary collapse

Constructor Details

#initialize(constants) ⇒ Proxy

Returns a new instance of Proxy.



122
123
124
# File 'lib/expression_processor.rb', line 122

def initialize(constants)
  @constants = constants
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(sym, *args, &block) ⇒ Object



126
127
128
# File 'lib/expression_processor.rb', line 126

def method_missing(sym, *args, &block)
  @constants[sym] || 0.0
end

Instance Method Details

#max(*values) ⇒ Object



130
131
132
133
# File 'lib/expression_processor.rb', line 130

def max(*values)
  values = values.flatten! || values
  values.max
end

#min(*values) ⇒ Object



135
136
137
138
# File 'lib/expression_processor.rb', line 135

def min(*values)
  values = values.flatten! || values
  values.min
end

#round(value) ⇒ Object



140
141
142
# File 'lib/expression_processor.rb', line 140

def round(value)
  value.to_f.round
end

#sum(*values) ⇒ Object



144
145
146
147
# File 'lib/expression_processor.rb', line 144

def sum(*values)
  values = values.flatten! || values
  values.inject(0.0) {|total, value| total += value if value.is_a?(Numeric) }
end