Class: Dcc::Validate::Schematron::Rules::IsoCodeValidation
- Inherits:
-
Base
- Object
- Dcc::Validate::Schematron::Rule
- Base
- Dcc::Validate::Schematron::Rules::IsoCodeValidation
- Defined in:
- lib/dcc/validate/schematron/rules/iso_code_validation.rb
Overview
Validates ISO 3166-1 (country) and ISO 639-1 (language) codes used in coreData. Custom type casts already enforce format; here we only flag empties that escaped earlier casts.
Instance Method Summary collapse
Methods inherited from Dcc::Validate::Schematron::Rule
Instance Method Details
#check_on(dcc) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/dcc/validate/schematron/rules/iso_code_validation.rb', line 12 def check_on(dcc) return [] unless Dcc::TypeGuards.has_attribute?(dcc, :administrative_data) core = safe_attr(dcc.administrative_data, :core_data) return [] if core.nil? issues = [] country = Dcc::TypeGuards.has_attribute?(core, :country_code_iso_3166_1) ? core.country_code_iso_3166_1 : nil if country.nil? || country.to_s.empty? issues << issue( severity: :error, message: "dcc:countryCodeISO3166_1 is missing", ) end used = Dcc::TypeGuards.has_attribute?(core, :used_lang_code_iso_639_1) ? Array(core.used_lang_code_iso_639_1) : [] issues << issue( severity: :error, message: "dcc:usedLangCodeISO639_1 must have at least one entry", ) if used.empty? mandatory = Dcc::TypeGuards.has_attribute?(core, :mandatory_lang_code_iso_639_1) ? Array(core.mandatory_lang_code_iso_639_1) : [] issues << issue( severity: :error, message: "dcc:mandatoryLangCodeISO639_1 must have at least one entry", ) if mandatory.empty? issues end |