Class: Ruleby::Ferrari::RulebookHelper
- Inherits:
-
Object
- Object
- Ruleby::Ferrari::RulebookHelper
- Defined in:
- lib/dsl/ferrari.rb
Instance Attribute Summary collapse
-
#engine ⇒ Object
readonly
Returns the value of attribute engine.
Instance Method Summary collapse
-
#initialize(engine) ⇒ RulebookHelper
constructor
A new instance of RulebookHelper.
- #rule(name, *args, &block) ⇒ Object
Constructor Details
#initialize(engine) ⇒ RulebookHelper
Returns a new instance of RulebookHelper.
15 16 17 |
# File 'lib/dsl/ferrari.rb', line 15 def initialize(engine) @engine = engine end |
Instance Attribute Details
#engine ⇒ Object (readonly)
Returns the value of attribute engine.
19 20 21 |
# File 'lib/dsl/ferrari.rb', line 19 def engine @engine end |
Instance Method Details
#rule(name, *args, &block) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/dsl/ferrari.rb', line 21 def rule(name, *args, &block) = args[0].kind_of?(Hash) ? args.shift : {} r = RuleBuilder.new name args.each do |arg| if arg.kind_of? Array r.when(*arg) else raise 'Invalid condition. All or none must be Arrays.' end end r.then(&block) r.priority = [:priority] if [:priority] @engine.assert_rule(r.build_rule) end |