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
Constructor Details
#initialize(**kwargs) ⇒ Base
Returns a new instance of Base.
32 33 34 35 36 37 38 39 40 |
# File 'lib/pubid/itu/identifiers/base.rb', line 32 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.
111 112 113 114 115 116 117 118 119 |
# File 'lib/pubid/itu/identifiers/base.rb', line 111 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
121 122 123 124 125 126 127 128 129 |
# File 'lib/pubid/itu/identifiers/base.rb', line 121 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
47 48 49 50 51 52 53 54 55 56 |
# File 'lib/pubid/itu/identifiers/base.rb', line 47 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
58 59 60 |
# File 'lib/pubid/itu/identifiers/base.rb', line 58 def publisher "ITU" end |
#render_base(**_opts) ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/pubid/itu/identifiers/base.rb', line 76 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
98 99 100 101 102 103 104 105 106 |
# File 'lib/pubid/itu/identifiers/base.rb', line 98 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.
71 72 73 74 |
# File 'lib/pubid/itu/identifiers/base.rb', line 71 def to_s(**opts) opts = self.class.normalize_to_s_opts(opts) render_base(**opts) + render_language_suffix end |