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 = {}, custom_functions = {}) ⇒ Object
-
#initialize(string) ⇒ Formula
constructor
A new instance of Formula.
- #validate(type_source = Kalculator::TypeSources.new(Hash.new)) ⇒ Object
Constructor Details
#initialize(string) ⇒ Formula
Returns a new instance of Formula.
6 7 8 9 |
# File 'lib/kalculator/formula.rb', line 6 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.
4 5 6 |
# File 'lib/kalculator/formula.rb', line 4 def ast @ast end |
#string ⇒ Object (readonly)
Returns the value of attribute string.
4 5 6 |
# File 'lib/kalculator/formula.rb', line 4 def string @string end |
Instance Method Details
#evaluate(data_source = {}, custom_functions = {}) ⇒ Object
15 16 17 |
# File 'lib/kalculator/formula.rb', line 15 def evaluate(data_source = {}, custom_functions = {}) Kalculator::Evaluator.new(data_source, custom_functions).evaluate(ast) end |
#validate(type_source = Kalculator::TypeSources.new(Hash.new)) ⇒ Object
11 12 13 |
# File 'lib/kalculator/formula.rb', line 11 def validate( type_source = Kalculator::TypeSources.new(Hash.new)) Kalculator::Validator.new(type_source).validate(ast) end |