Class: Kalculator::Formula
- Inherits:
-
Object
- Object
- Kalculator::Formula
- Defined in:
- lib/kalculator/formula.rb
Instance Attribute Summary collapse
-
#ast ⇒ Object
readonly
Returns the value of attribute ast.
-
#string ⇒ Object
readonly
Returns the value of attribute string.
Instance Method Summary collapse
- #evaluate(data_source = {}) ⇒ Object
-
#initialize(string) ⇒ Formula
constructor
A new instance of Formula.
Constructor Details
#initialize(string) ⇒ Formula
5 6 7 8 |
# File 'lib/kalculator/formula.rb', line 5 def initialize(string) @ast = Kalculator::Parser.parse(Kalculator::Lexer.lex(string)) @string = string end |
Instance Attribute Details
#ast ⇒ Object (readonly)
Returns the value of attribute ast.
3 4 5 |
# File 'lib/kalculator/formula.rb', line 3 def ast @ast end |
#string ⇒ Object (readonly)
Returns the value of attribute string.
3 4 5 |
# File 'lib/kalculator/formula.rb', line 3 def string @string end |
Instance Method Details
#evaluate(data_source = {}) ⇒ Object
10 11 12 |
# File 'lib/kalculator/formula.rb', line 10 def evaluate(data_source = {}) Kalculator::Evaluator.new(data_source).evaluate(ast) end |