Class: Ruleby::LeTigre::RulebookHelper
- Inherits:
-
Object
- Object
- Ruleby::LeTigre::RulebookHelper
- Defined in:
- lib/dsl/letigre.rb
Instance Attribute Summary collapse
-
#engine ⇒ Object
readonly
Returns the value of attribute engine.
Instance Method Summary collapse
-
#initialize(engine, rulebook) ⇒ RulebookHelper
constructor
A new instance of RulebookHelper.
- #rule(name, *args, &then_block) ⇒ Object
Constructor Details
#initialize(engine, rulebook) ⇒ RulebookHelper
Returns a new instance of RulebookHelper.
16 17 18 19 |
# File 'lib/dsl/letigre.rb', line 16 def initialize(engine, rulebook) @rulebook = rulebook @engine = engine end |
Instance Attribute Details
#engine ⇒ Object (readonly)
Returns the value of attribute engine.
21 22 23 |
# File 'lib/dsl/letigre.rb', line 21 def engine @engine end |
Instance Method Details
#rule(name, *args, &then_block) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/dsl/letigre.rb', line 23 def rule(name, *args, &then_block) if args.empty? raise 'No conditions supplied.' end = args[0].kind_of?(Hash) ? args.shift : {} pb = PatternParser.new @rulebook pattern = pb.parse args rb = RuleBuilder.new name rb.when(pattern) rb.then(&then_block) rb.priority = [:priority] if [:priority] @engine.assert_rule rb.build_rule end |