Class: J2119::OnlyOneOfConstraint
- Inherits:
-
Constraint
- Object
- Constraint
- J2119::OnlyOneOfConstraint
- Defined in:
- lib/j2119/constraints.rb
Overview
Verify that there is only one of a selection of fields
Instance Method Summary collapse
- #check(node, path, problems) ⇒ Object
-
#initialize(fields) ⇒ OnlyOneOfConstraint
constructor
A new instance of OnlyOneOfConstraint.
Methods inherited from Constraint
Constructor Details
#initialize(fields) ⇒ OnlyOneOfConstraint
Returns a new instance of OnlyOneOfConstraint.
42 43 44 45 |
# File 'lib/j2119/constraints.rb', line 42 def initialize(fields) super() @fields = fields end |
Instance Method Details
#check(node, path, problems) ⇒ Object
47 48 49 50 51 52 |
# File 'lib/j2119/constraints.rb', line 47 def check(node, path, problems) if (@fields & node.keys).size > 1 problems << "#{path} may have only one of #{@fields}" end end |