Class: Ruleset
Instance Method Summary collapse
- #add_points(points, criteria) ⇒ Object
- #evaluate(instance) ⇒ Object
-
#initialize ⇒ Ruleset
constructor
A new instance of Ruleset.
- #remove_points(points, criteria) ⇒ Object
Constructor Details
#initialize ⇒ Ruleset
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 |