Class: CodeDrivenDevelopment::Rule::Set
- Inherits:
-
Object
- Object
- CodeDrivenDevelopment::Rule::Set
- Defined in:
- lib/code_driven_development/rule/set.rb
Instance Method Summary collapse
-
#initialize(*rules, default: nil) ⇒ Set
constructor
A new instance of Set.
- #test_for(code, test_context) ⇒ Object
Constructor Details
#initialize(*rules, default: nil) ⇒ Set
Returns a new instance of Set.
4 5 6 7 |
# File 'lib/code_driven_development/rule/set.rb', line 4 def initialize(*rules, default: nil) @rules = rules @default_rule = default end |
Instance Method Details
#test_for(code, test_context) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/code_driven_development/rule/set.rb', line 9 def test_for(code, test_context) capable_rules = rules.map do |klass| klass.new(code, self, test_context) end.select(&:capable?) case capable_rules.count when 0 default_rule.new(code, self, test_context).test when 1 capable_rules.first.test else raise "Multiple rules matched #{code.inspect}:\n\t" + capable_rules.map(&:class).map(&:to_s).join("\n\t") end end |