Class: Pubid::Bsi::Identifiers::ConsolidatedIdentifier

Inherits:
Base
  • Object
show all
Defined in:
lib/pubid/bsi/identifiers/consolidated_identifier.rb

Overview

Consolidated Identifier - contains base document plus supplements Example: “BS 4592-0:2006+A1:2012” = [BS 4592-0:2006, Amendment 1:2012]

Instance Method Summary collapse

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, #urn_supplement_type, #urn_type_code

Constructor Details

This class inherits a constructor from Pubid::Identifier

Instance Method Details

#dateObject



130
131
132
133
# File 'lib/pubid/bsi/identifiers/consolidated_identifier.rb', line 130

def date
  base = identifiers&.first
  base.date if base&.class&.attributes&.key?(:date)
end

#numberObject



121
122
123
# File 'lib/pubid/bsi/identifiers/consolidated_identifier.rb', line 121

def number
  identifiers&.first&.number
end

#partObject



140
141
142
143
# File 'lib/pubid/bsi/identifiers/consolidated_identifier.rb', line 140

def part
  base = identifiers&.first
  base.part if base&.class&.attributes&.key?(:part)
end

#partsObject



135
136
137
138
# File 'lib/pubid/bsi/identifiers/consolidated_identifier.rb', line 135

def parts
  base = identifiers&.first
  base.parts if base&.class&.attributes&.key?(:parts)
end

#publisherObject

Delegate to first identifier (base document)



117
118
119
# File 'lib/pubid/bsi/identifiers/consolidated_identifier.rb', line 117

def publisher
  identifiers&.first&.publisher
end

#to_s(lang: :en, lang_single: false) ⇒ Object



11
12
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/pubid/bsi/identifiers/consolidated_identifier.rb', line 11

def to_s(lang: :en, lang_single: false)
  base_id = identifiers.first

  # Render base without suffixes (will add them after supplements)
  result = if base_id.is_a?(Base) && base_id.class.method_defined?(:to_s_without_suffixes)
             base_id.to_s_without_suffixes
           else
             # Temporarily remove suffixes for rendering
             base_str = base_id.to_s
             # Remove known suffixes (more flexible patterns to handle topics)
             base_str = base_str.sub(/ ExComm \(.*?\)$/, "") # ExComm (Fire)
               .sub(/ ExComm$/, "") # ExComm without topic
               .sub(/ - TC$/, "")
               .sub(/ PDF$/, "")
               .sub(/ \([A-Z][a-z]+\)$/, "")
             base_str
           end

  # Add supplements
  identifiers[1..].each do |id|
    if id.is_a?(Amendment)
      if id.amendment_year
        sep = id.is_a?(Base) && id.separator ? id.separator : "+"
        result += "#{sep}A#{id.amendment_number}:#{id.amendment_year}"
      else
        # Letter suffixes (AA, AB, etc.) have a space, numeric suffixes don't
        result += if id.amendment_number&.match?(/^[A-Z]+$/)
                    " AMD #{id.amendment_number}"
                  else
                    " AMD#{id.amendment_number}"
                  end
      end
    elsif id.is_a?(Corrigendum)
      sep = id.is_a?(Base) && id.separator ? id.separator : "+"
      result += "#{sep}C"
      result += id.corrigendum_number.to_s if id.corrigendum_number
      result += ":#{id.corrigendum_year}" if id.corrigendum_year
    else
      result += id.to_s
    end
  end

  # Add suffixes from base identifier AFTER supplements
  if base_id.is_a?(Pubid::Identifier)
    base_attrs = base_id.class.attributes
    ec = base_attrs.key?(:expert_commentary) ? base_id.expert_commentary : nil
    if ec
      ect = base_attrs.key?(:expert_commentary_topic) ? base_id.expert_commentary_topic : nil
      result += ect ? " ExComm (#{ect})" : " ExComm"
    end

    tc = base_attrs.key?(:tracked_changes) ? base_id.tracked_changes : nil
    result += " - TC" if tc

    # Translation - preserve the "version" or "Translation" suffix if present
    tl = base_attrs.key?(:translation_lang) ? base_id.translation_lang : nil
    if tl
      ts_type = base_attrs.key?(:translation_suffix_type) ? base_id.translation_suffix_type : nil
      result += if ts_type == "version"
                  " (#{tl} version)"
                elsif ts_type == "Translation"
                  " (#{tl} Translation)"
                else
                  " (#{tl})"
                end
    else
      tu = base_attrs.key?(:translation_upper) ? base_id.translation_upper : nil
      if tu
        ts_type = base_attrs.key?(:translation_suffix_type) ? base_id.translation_suffix_type : nil
        result += if ts_type == "Translation"
                    " (#{tu} Translation)"
                  else
                    " (#{tu})"
                  end
      end
    end

    # Reaffirmation notation like (R2004)
    ry = base_attrs.key?(:reaffirmation_year) ? base_id.reaffirmation_year : nil
    result += " (R#{ry})" if ry
  end

  result
end

#to_urnObject



96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/pubid/bsi/identifiers/consolidated_identifier.rb', line 96

def to_urn
  base = identifiers&.first
  return nil unless base

  urn = base.to_urn if base.class.method_defined?(:to_urn)
  return urn unless urn

  # Append supplement info to URN
  identifiers[1..].each do |id|
    if id.is_a?(Amendment)
      urn += ":amd:#{id.amendment_number}"
      urn += ":#{id.amendment_year}" if id.amendment_year
    elsif id.is_a?(Corrigendum)
      urn += ":cor:#{id.corrigendum_number}"
      urn += ":#{id.corrigendum_year}" if id.corrigendum_year
    end
  end
  urn
end

#typeObject



145
146
147
148
# File 'lib/pubid/bsi/identifiers/consolidated_identifier.rb', line 145

def type
  base = identifiers&.first
  base.type if base&.class&.attributes&.key?(:type)
end

#yearObject



125
126
127
128
# File 'lib/pubid/bsi/identifiers/consolidated_identifier.rb', line 125

def year
  base = identifiers&.first
  base.year if base&.class&.attributes&.key?(:year)
end