Class: Opencdd::Validator::EnumRule

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

Constant Summary

Constants inherited from Rule

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
13
# File 'lib/opencdd/validator/enum_rule.rb', line 10

def applies?(context)
  return false unless context.data_type
  context.data_type.to_s.start_with?("ENUM_")
end

#call(value, context) ⇒ Object



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

def call(value, context)
  return true if value.nil? || value.to_s.strip.empty?
  terms = context.enum_terms_for(context.data_type)
  return true if terms.empty?
  terms.any? { |t| t.to_s == value.to_s }
end

#idObject



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

def id
  "R04"
end

#message(value, _context) ⇒ Object



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

def message(value, _context)
  "R04: #{value.inspect} is not a member of the value list"
end