Class: Opencdd::Validator::ReferenceRule

Inherits:
Rule
  • Object
show all
Defined in:
lib/opencdd/validator/reference_rule.rb

Constant Summary

Constants inherited from Rule

Opencdd::Validator::Rule::REFERENCE_VALUE_KINDS

Instance Method Summary collapse

Methods inherited from Rule

#blank?, #code_column?, #reference_kind?, #skip_blank?, #value_passes?

Instance Method Details

#applies?(context) ⇒ Boolean

Returns:

  • (Boolean)


10
11
12
# File 'lib/opencdd/validator/reference_rule.rb', line 10

def applies?(context)
  %i[identifier_ref set_of_refs class_ref].include?(context.value_kind)
end

#call(value, context) ⇒ Object



14
15
16
17
18
19
20
21
# File 'lib/opencdd/validator/reference_rule.rb', line 14

def call(value, context)
  return true if value.nil? || value.to_s.strip.empty?
  return false unless context.database
  refs(value).all? do |ref|
    parsed = Opencdd::IRDI.parse(ref)
    context.database.find(parsed) || context.database.find_by_code(ref.to_s)
  end
end

#idObject



6
7
8
# File 'lib/opencdd/validator/reference_rule.rb', line 6

def id
  "R08"
end

#message(value, _context) ⇒ Object



23
24
25
# File 'lib/opencdd/validator/reference_rule.rb', line 23

def message(value, _context)
  "R08: reference #{value.inspect} does not resolve in this database"
end