Class: Pubid::Iec::SupplementIdentifier

Inherits:
SingleIdentifier show all
Defined in:
lib/pubid/iec/supplement_identifier.rb

Overview

Identifier that represents a supplement to a base identifier.

Instance Method Summary collapse

Methods inherited from SingleIdentifier

#edition_portion, #language_portion, #number_portion, #publisher_portion

Methods inherited from Identifier

parse

Methods inherited from Pubid::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

#base_identifierObject

Override base_identifier getter to ensure it’s always created for standalone supplements



12
13
14
# File 'lib/pubid/iec/supplement_identifier.rb', line 12

def base_identifier
  @base_identifier || ensure_base_identifier
end

#copublishersObject



48
49
50
51
52
# File 'lib/pubid/iec/supplement_identifier.rb', line 48

def copublishers
  return @copublishers if @ensuring_base

  @copublishers || base_identifier&.copublishers
end

#ensure_base_identifierObject

Ensure we have a base_identifier for standalone supplements Creates a synthetic base identifier from supplement attributes if needed Returns the base_identifier



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
95
96
97
98
99
100
101
102
103
# File 'lib/pubid/iec/supplement_identifier.rb', line 57

def ensure_base_identifier
  return @base_identifier if @base_identifier

  # Guard flag to prevent recursion in number getter
  @ensuring_base = true

  # For standalone supplements like "IEC/FDAM 60038-1"
  # The supplement number is in the `part` attribute, while `number` is the base number
  # We need to create a synthetic base and use part as the supplement number
  return nil unless publisher && (number || part)

  # Capture original values BEFORE marking as synthetic
  # (otherwise our getters will return swapped values)
  base_number = number
  supplement_number = part

  # NOW mark that this is a synthetic base (after capturing values)
  @synthetic_base = true

  # Use SingleIdentifier which has typed_stage attribute
  base = SingleIdentifier.new
  base.publisher = publisher
  base.number = base_number if base_number
  base.part = nil # Base doesn't have part - part is the supplement number
  base.subpart = subpart if subpart
  base.date = date if date

  # Create typed_stage for the base - use "IS" (International Standard) type
  # not the supplement type
  require_relative "../components/typed_stage"
  base.typed_stage = Pubid::Components::TypedStage.new(
    abbr: ["IS"],
    type_code: :is,
    stage_code: :undated,
  )

  @base_identifier = base

  # Store the supplement number for getter override
  # The original number is the base number (moved to base_identifier)
  # The original part is the supplement number (what we want to return)
  @supplement_number = supplement_number

  @base_identifier
ensure
  @ensuring_base = false
end

#numberObject

Override number getter to trigger swap for standalone supplements



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/pubid/iec/supplement_identifier.rb', line 17

def number
  # Guard against recursion in ensure_base_identifier
  return @number if @ensuring_base

  # For standalone supplements, trigger base creation first
  ensure_base_identifier if @synthetic_base.nil? && publisher && part

  if @synthetic_base
    @supplement_number || @number
  else
    super
  end
end

#partObject

Override part getter for standalone supplements (part becomes nil after swap)



32
33
34
35
36
37
38
39
# File 'lib/pubid/iec/supplement_identifier.rb', line 32

def part
  # For standalone supplements with synthetic base, part is nil (moved to number)
  if @synthetic_base
    nil
  else
    super
  end
end

#publisherObject

Delegate publisher and copublishers to base_identifier if not set



42
43
44
45
46
# File 'lib/pubid/iec/supplement_identifier.rb', line 42

def publisher
  return @publisher if @ensuring_base

  @publisher || base_identifier&.publisher
end

#synthetic_base?Boolean

Check if this supplement has a synthetic base (created for standalone format)

Returns:

  • (Boolean)


106
107
108
# File 'lib/pubid/iec/supplement_identifier.rb', line 106

def synthetic_base?
  @synthetic_base ||= false
end

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



110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# File 'lib/pubid/iec/supplement_identifier.rb', line 110

def to_s(lang: :en, lang_single: false, with_edition: false)
  # Ensure we have a base_identifier for standalone supplements
  ensure_base_identifier

  # For standalone supplements (synthetic base), use standalone format
  # IEC/FDAM 60038-1, not IEC/IS 60038/FDAM1
  if synthetic_base?
    parts = []

    # Publisher portion
    if publisher
      parts << publisher.body
      parts << "/#{copublishers.map(&:body).join('/')}" if copublishers&.any?
    end

    # Supplement type and number with part (use base number)
    abbr = typed_stage.abbr.first
    number_str = base_identifier.number.to_s
    number_str += "-#{number}" if number # supplement number
    number_str += "-#{subpart}" if subpart
    parts << "#{abbr} #{number_str}"

    result = parts.join("/")
    result += ":#{date.year}" if date
    result += " #{edition}" if edition&.number
    result
  elsif base_identifier
    # Normal supplement with real base identifier
    # Format: "IEC 60050-102:2007/AMD1:2017"
    parts = []
    parts << base_identifier.to_s(lang: lang, lang_single: lang_single,
                                  with_edition: with_edition)

    # Supplement notation
    # Use uppercase abbreviation without space: /AMD1, /COR1
    abbr = typed_stage.abbr.first.upcase
    supp_part = "/#{abbr}#{number}"
    supp_part += ":#{date.year}" if date
    parts << supp_part

    # Add edition if present
    parts << " #{edition}" if edition&.number

    parts.join
  else
    # Fallback - shouldn't happen
    super
  end
end