Class: Pubid::Oiml::Identifiers::Annex

Inherits:
SupplementIdentifier show all
Defined in:
lib/pubid/oiml/identifiers/annex.rb

Instance Method Summary collapse

Methods inherited from Pubid::Oiml::Identifier

#to_urn

Methods inherited from 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_supplement_s, #to_urn, #urn_supplement_type, #urn_type_code

Constructor Details

This class inherits a constructor from Pubid::Identifier

Instance Method Details

#supplement_typeObject



9
10
11
# File 'lib/pubid/oiml/identifiers/annex.rb', line 9

def supplement_type
  letter ? "Annex #{letter}" : "Annexes"
end

#to_s(format: nil) ⇒ Object



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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/pubid/oiml/identifiers/annex.rb', line 13

def to_s(format: nil)
  # Determine base format from its parsed_format
  base_format = if base_identifier.class.attributes.key?(:parsed_format) && base_identifier.parsed_format == "long"
                  :long
                else
                  :short
                end

  # Use format parameter or annex's own parsed_format
  annex_format = if format
                   format
                 elsif self.class.attributes.key?(:parsed_format) && parsed_format == "long"
                   :long
                 else
                   :short
                 end

  # Annexes have different pattern than amendments
  base_str = base_identifier.to_s(format: base_format)
  result = base_str.sub(/:.*/, "").sub(/\s+Edition\s+\d{4}/, "").sub(
    /\(.*\)/, ""
  ).strip
  if letter
    # Specific annex: "OIML R 60 Annex A Edition 2013 (E)"
    result += " Annex #{letter}"

    result += " Edition #{year}" if year

  # Supplements ALWAYS use space before language

  else
    # General annexes: "OIML R 60 Annexes Edition 2021 (E)" or "OIML R 60 Annexes:2021 (E)"
    result += " Annexes"

    if year
      result += annex_format == :long ? " Edition #{year}" : ":#{year}"
    elsif base_identifier.date
      result += annex_format == :long ? " Edition #{base_identifier.date.year}" : ":#{base_identifier.date.year}"
    end

    # Supplements ALWAYS use space before language

  end
  result += " (#{language})" if language
  result
end