Class: Ruleby::Ferrari::RulebookHelper

Inherits:
Object
  • Object
show all
Defined in:
lib/dsl/ferrari.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#engineObject (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) 
  options = 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 = options[:priority] if options[:priority]
  
  @engine.assert_rule(r.build_rule)
end