Class: Pubid::Itu::Identifiers::Annex

Inherits:
Pubid::Itu::Identifier show all
Defined in:
lib/pubid/itu/identifiers/annex.rb

Overview

"Annex to ..." identifier — the document IS the annex of a Special Publication (e.g. an annex to ITU OB), not a sub-annex with a number.

Three rendering forms (per v1 PR #38):

* default (no i18n_lang): English structural, "Annex to ITU OB No. 1000"
* short with i18n_lang: structural translation using `annex_to`
* long with i18n_lang + format: :long: per-language `annex_long` template

Languages without an annex_to entry (fr/es/ru/zh) use the long template for the short form too.

Constant Summary

Constants inherited from Pubid::Itu::Identifier

Pubid::Itu::Identifier::LANGUAGES

Instance Method Summary collapse

Methods inherited from Pubid::Itu::Identifier

#base_from_kv, #base_to_kv, #code_for, #common_text_twin_from_kv, #common_text_twin_to_kv, #date_for, #emit_kv, #exclude_from_nested, #imp_marker_from_kv, #imp_marker_to_kv, #initialize, #month_from_kv, #month_to_kv, #mr_number_with_part, #mr_publisher, #mr_type, normalize_to_s_opts, #number, #number_from_kv, #number_to_kv, parse, #parts_from_kv, #parts_to_kv, #qualifier_from_kv, #qualifier_glued_from_kv, #qualifier_glued_to_kv, #qualifier_to_kv, #render_date_suffix, #render_language_suffix, #sector_from_kv, #sector_to_kv, #series_from_kv, #series_suffix_from_kv, #series_suffix_spaced_from_kv, #series_suffix_spaced_to_kv, #series_suffix_to_kv, #series_to_kv, #subseries_from_kv, #subseries_to_kv, #to_s, #year_from_kv, #year_to_kv

Methods inherited from Pubid::Identifier

apply_mappings, #base, #base_document, concrete_class_for, #dated_version_of?, #draft_of?, #drop_supplements, #edition_of?, #eql?, #exclude, from_hash, #has_supplement?, #hash, #includes?, #initialize, #matches?, #mr_all_parts, #mr_edition, #mr_languages, #mr_number, #mr_number_with_part, #mr_part, #mr_publisher, #mr_subpart, #mr_supplement_suffix, #mr_type, #mr_year, #new_edition_of?, polymorphic_name, polymorphic_type_map, #related_to?, #render, #resolve_urn_generator, #root, #sibling_of?, #supplement_of?, #to_hash, #to_mr_string, #to_s, #to_slug, #to_supplement_s, #urn_supplement_type, #urn_type_code, #year

Constructor Details

This class inherits a constructor from Pubid::Itu::Identifier

Instance Method Details

#==(other) ⇒ Object



63
64
65
66
67
# File 'lib/pubid/itu/identifiers/annex.rb', line 63

def ==(other)
  return false unless other.is_a?(Annex)

  base == other.base && language == other.language
end

#render_base(**opts) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/pubid/itu/identifiers/annex.rb', line 37

def render_base(**opts)
  lang = opts[:i18n_lang]&.to_s
  long_template = lang && Pubid::Itu::I18N["annex_long"]&.fetch(lang,
                                                                nil)

  if opts[:format] == :long && long_template
    return long_template % { number: base_number }
  end

  annex_translation = lang && Pubid::Itu::I18N["annex_to"]&.fetch(lang,
                                                                  nil)

  if annex_translation
    base_str = base_render(**opts)
    return "#{base_str} #{annex_translation}" if lang == "ar"

    return "#{annex_translation} #{base_str}"
  end

  if long_template
    return long_template % { number: base_number }
  end

  "Annex to #{base_render(**opts)}"
end

#to_urnObject



29
30
31
32
33
34
35
# File 'lib/pubid/itu/identifiers/annex.rb', line 29

def to_urn
  # Annex URN: append :annex to the inner identifier's URN.
  base_urn = base&.to_urn
  return "urn:itu:annex" unless base_urn

  "#{base_urn}:annex"
end