Class: Ruleset

Inherits:
Object show all
Defined in:
lib/scoring_rules/ruleset.rb

Instance Method Summary collapse

Constructor Details

#initializeRuleset

Returns a new instance of Ruleset.



2
3
4
# File 'lib/scoring_rules/ruleset.rb', line 2

def initialize
  @rules = []
end

Instance Method Details

#add_points(points, criteria) ⇒ Object



6
7
8
# File 'lib/scoring_rules/ruleset.rb', line 6

def add_points(points, criteria)
  add_rule create_rule(points, criteria)
end

#evaluate(instance) ⇒ Object



14
15
16
17
18
# File 'lib/scoring_rules/ruleset.rb', line 14

def evaluate(instance)
  @rules.inject(0) do |memo, rule|
    memo += rule.evaluate(instance)
  end
end

#remove_points(points, criteria) ⇒ Object



10
11
12
# File 'lib/scoring_rules/ruleset.rb', line 10

def remove_points(points, criteria)
  add_rule create_rule(points, criteria, :multiplier => -1)
end