Class: J2119::OnlyOneOfConstraint

Inherits:
Constraint show all
Defined in:
lib/j2119/constraints.rb

Overview

Verify that there is only one of a selection of fields

Instance Method Summary collapse

Methods inherited from Constraint

#add_condition, #applies

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