Class: Pubid::Itu::Identifiers::Base
- Inherits:
-
Pubid::Identifier
- Object
- Lutaml::Model::Serializable
- Pubid::Identifier
- Pubid::Itu::Identifiers::Base
- Defined in:
- lib/pubid/itu/identifiers/base.rb
Overview
Base class for all ITU identifiers
Direct Known Subclasses
Annex, CombinedIdentifier, Recommendation, SpecialPublication, Supplement
Constant Summary collapse
- LANGUAGES =
Long-form ↔ ITU single-letter language code map. The parser produces single-letter codes (E/F/S/R/A/C); API callers (e.g. metanorma-itu) pass long-form (en/fr/es/ru/ar/zh). Storage is normalized to the single-letter form. Languages with no canonical letter (e.g. “de”) pass through unchanged and produce no trailing suffix.
{ "fr" => "F", "es" => "S", "ru" => "R", "ar" => "A", "zh" => "C", "en" => "E", "F" => "F", "S" => "S", "R" => "R", "A" => "A", "C" => "C", "E" => "E" }.freeze
Class Method Summary collapse
-
.normalize_to_s_opts(opts) ⇒ Object
Translate ‘language:` opt to `i18n_lang:` opt.
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#base_hash ⇒ Object
Override base_hash to handle ITU-specific attributes.
-
#initialize(**kwargs) ⇒ Base
constructor
A new instance of Base.
- #publisher ⇒ Object
- #render_base(**_opts) ⇒ Object
- #render_language_suffix ⇒ Object
-
#to_s(**opts) ⇒ Object
Render identifier as a string.
Methods inherited from Pubid::Identifier
#base_identifier, #eql?, #exclude, #hash, #mr_number, #mr_number_with_part, #mr_part, #mr_publisher, #mr_type, #mr_year, #new_edition_of?, polymorphic_name, #render, #resolve_urn_generator, #root, #to_mr_string, #to_supplement_s, #to_urn, #urn_supplement_type, #urn_type_code, #year
Constructor Details
#initialize(**kwargs) ⇒ Base
Returns a new instance of Base.
26 27 28 29 30 31 32 33 34 |
# File 'lib/pubid/itu/identifiers/base.rb', line 26 def initialize(**kwargs) if kwargs[:language] kwargs = kwargs.merge(language: normalize_language(kwargs[:language])) end super validate_ob_no_sector! end |
Class Method Details
.normalize_to_s_opts(opts) ⇒ Object
Translate ‘language:` opt to `i18n_lang:` opt. v1 PR #38 introduced `i18n_lang:` to disambiguate “rendering language” from the document language attribute; `language:` remains a deprecated alias.
105 106 107 108 109 110 111 112 113 |
# File 'lib/pubid/itu/identifiers/base.rb', line 105 def self.normalize_to_s_opts(opts) opts = opts.dup if opts.key?(:language) && !opts.key?(:i18n_lang) opts[:i18n_lang] = opts.delete(:language) else opts.delete(:language) end opts end |
Instance Method Details
#==(other) ⇒ Object
115 116 117 118 119 120 121 122 123 |
# File 'lib/pubid/itu/identifiers/base.rb', line 115 def ==(other) return false unless other.is_a?(Base) sector == other.sector && series == other.series && code == other.code && date == other.date && language == other.language end |
#base_hash ⇒ Object
Override base_hash to handle ITU-specific attributes
41 42 43 44 45 46 47 48 49 50 |
# File 'lib/pubid/itu/identifiers/base.rb', line 41 def base_hash hash = super # ITU Series has a 'series' attribute, not 'number' if hash[:series].is_a?(Hash) && series hash[:series] = series.series end # Add sector (ITU-specific, has a 'sector' attribute) hash[:sector] = sector.sector if sector hash end |
#publisher ⇒ Object
52 53 54 |
# File 'lib/pubid/itu/identifiers/base.rb', line 52 def publisher "ITU" end |
#render_base(**_opts) ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/pubid/itu/identifiers/base.rb', line 70 def render_base(**_opts) result = "#{publisher}-#{sector}" # Add series and code result += if series " #{series}.#{code}" else " #{code}" end # Add date if present if date result += if date.month " (#{date.month}/#{date.year})" else " (#{date.year})" end end result end |
#render_language_suffix ⇒ Object
92 93 94 95 96 97 98 99 100 |
# File 'lib/pubid/itu/identifiers/base.rb', line 92 def render_language_suffix return "" unless language # Only render canonical single-letter ITU language codes # (e.g. "F", "S"). Languages with no mapping (e.g. "de") get # no suffix — matches v1 PR #38 render_language behavior. return "" unless LANGUAGES.value?(language) "-#{language}" end |
#to_s(**opts) ⇒ Object
Render identifier as a string.
65 66 67 68 |
# File 'lib/pubid/itu/identifiers/base.rb', line 65 def to_s(**opts) opts = self.class.normalize_to_s_opts(opts) render_base(**opts) + render_language_suffix end |