Class: Grammoire::EvaluationContext
- Inherits:
-
Object
- Object
- Grammoire::EvaluationContext
- Defined in:
- lib/grammoire/evaluation_context.rb
Instance Method Summary collapse
- #data(name) ⇒ Object
- #eval(rule) ⇒ Object
-
#initialize(grammar) ⇒ EvaluationContext
constructor
A new instance of EvaluationContext.
- #with_data_points(data) ⇒ Object
Constructor Details
#initialize(grammar) ⇒ EvaluationContext
Returns a new instance of EvaluationContext.
5 6 7 8 |
# File 'lib/grammoire/evaluation_context.rb', line 5 def initialize(grammar) @grammar = grammar with_data_points({}) end |
Instance Method Details
#data(name) ⇒ Object
14 15 16 17 18 |
# File 'lib/grammoire/evaluation_context.rb', line 14 def data(name) raise GrammarError.new("Data point '#{name}' doesn't exist in the evaluation context.") unless @data.has_key? name return @data[name] end |
#eval(rule) ⇒ Object
20 21 22 |
# File 'lib/grammoire/evaluation_context.rb', line 20 def eval(rule) @grammar.evaluate(rule, @data) end |
#with_data_points(data) ⇒ Object
10 11 12 |
# File 'lib/grammoire/evaluation_context.rb', line 10 def with_data_points(data) @data = data end |