Class: Grammoire::Grammar
- Inherits:
-
Object
- Object
- Grammoire::Grammar
- Defined in:
- lib/grammoire/grammar.rb
Instance Method Summary collapse
- #context(context_class) ⇒ Object
- #evaluate(rule_name, data = {}) ⇒ Object
-
#initialize(random_generator = RandomGenerator.new) ⇒ Grammar
constructor
A new instance of Grammar.
- #rule(name, &action) ⇒ Object
Constructor Details
#initialize(random_generator = RandomGenerator.new) ⇒ Grammar
Returns a new instance of Grammar.
4 5 6 7 8 |
# File 'lib/grammoire/grammar.rb', line 4 def initialize(random_generator = RandomGenerator.new) @rules = [] @chooser = RuleChooser.new(random_generator) context(EvaluationContext) end |
Instance Method Details
#context(context_class) ⇒ Object
10 11 12 |
# File 'lib/grammoire/grammar.rb', line 10 def context(context_class) @context = context_class.new(self) end |
#evaluate(rule_name, data = {}) ⇒ Object
18 19 20 21 22 |
# File 'lib/grammoire/grammar.rb', line 18 def evaluate(rule_name, data = {}) @context.with_data_points(data) return @chooser.select_from(rules_for(rule_name)).evaluate(@context) end |