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

Inherits:
Base 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 Base

Base::LANGUAGES

Instance Method Summary collapse

Methods inherited from Base

#base_hash, #initialize, normalize_to_s_opts, #publisher, #render_language_suffix, #to_s

Methods inherited from Pubid::Identifier

#base_identifier, #eql?, #exclude, #hash, #initialize, #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_s, #to_supplement_s, #urn_supplement_type, #urn_type_code

Constructor Details

This class inherits a constructor from Pubid::Itu::Identifiers::Base

Instance Method Details

#==(other) ⇒ Object



54
55
56
57
58
# File 'lib/pubid/itu/identifiers/annex.rb', line 54

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

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

#render_base(**opts) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/pubid/itu/identifiers/annex.rb', line 28

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



20
21
22
23
24
25
26
# File 'lib/pubid/itu/identifiers/annex.rb', line 20

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