Class: Opencdd::Validator::IrdiRule

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

Constant Summary collapse

FULL_PATTERN =
%r{
  \A
  [^/#\s]+
  /
  [^/#\s]*
  ///
  [^/#\s]+
  \#
  [^#\s]+
  (?:\#\#\d+)?
  (?:\#\#\#[^#]+)?
  \z
}x.freeze
SHORT_PATTERN =
/\A[A-Za-z0-9_]+\z/.freeze

Constants inherited from Rule

Rule::REFERENCE_VALUE_KINDS

Instance Method Summary collapse

Methods inherited from Rule

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

Instance Method Details

#applies?(context) ⇒ Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/opencdd/validator/irdi_rule.rb', line 26

def applies?(context)
  code_column?(context) || reference_column?(context)
end

#call(value, context) ⇒ Object



30
31
32
33
34
35
36
37
38
# File 'lib/opencdd/validator/irdi_rule.rb', line 30

def call(value, context)
  return true if value.nil? || value.to_s.strip.empty?
  s = value.to_s.strip
  if reference_column?(context)
    return true unless Opencdd::IRDI.parse(s).nil?
    return false
  end
  FULL_PATTERN.match?(s) || SHORT_PATTERN.match?(s) ? true : false
end

#idObject



22
23
24
# File 'lib/opencdd/validator/irdi_rule.rb', line 22

def id
  "R01"
end

#message(value, _context) ⇒ Object



40
41
42
# File 'lib/opencdd/validator/irdi_rule.rb', line 40

def message(value, _context)
  "R01: malformed IRDI/ICID #{value.inspect}"
end