Class: Pubid::BundledIdentifier

Inherits:
Identifier
  • Object
show all
Defined in:
lib/pubid/bundled_identifier.rb

Overview

Identifier that represents a combined bundle of documents using the + operator. Examples:

EN 10077-1:2006+AC:2009+AC2:2009
ISO/IEC DIR 1 + IEC SUP:2016-05
ISO 8601:2019+Amd 1:2024+Cor 1:2025

Semantic: Base document combined with amendments/corrigenda that are applied together This is different from:

/ operator (SupplementIdentifier) - supplement of a document
| operator (CombinedIdentifier) - dual-published by multiple organizations

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

#<=>(other) ⇒ Object

Support comparison for sorting



117
118
119
120
121
122
123
124
# File 'lib/pubid/bundled_identifier.rb', line 117

def <=>(other)
  return nil unless other.is_a?(BundledIdentifier)

  base_comparison = base_document.to_s <=> other.base_document.to_s
  return base_comparison unless base_comparison.zero?

  supplements.map(&:to_s).sort <=> other.supplements.map(&:to_s).sort
end

#copublishersObject



25
26
27
# File 'lib/pubid/bundled_identifier.rb', line 25

def copublishers
  base_document&.copublishers
end

#dateObject



33
34
35
# File 'lib/pubid/bundled_identifier.rb', line 33

def date
  base_document&.date
end

#numberObject



29
30
31
# File 'lib/pubid/bundled_identifier.rb', line 29

def number
  base_document&.number
end

#publisherObject

Delegate common attributes to base_document for easier access



21
22
23
# File 'lib/pubid/bundled_identifier.rb', line 21

def publisher
  base_document&.publisher
end

#stageObject



41
42
43
# File 'lib/pubid/bundled_identifier.rb', line 41

def stage
  base_document&.stage
end

#to_s(lang: :en, lang_single: false, with_edition: false, format: nil, stage_format_long: nil, with_date: nil) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/pubid/bundled_identifier.rb', line 49

def to_s(lang: :en, lang_single: false, with_edition: false, format: nil,
stage_format_long: nil, with_date: nil)
  result = base_document.to_s(lang: lang, lang_single: lang_single,
                              with_edition: with_edition, format: format, stage_format_long: stage_format_long, with_date: with_date)

  supplements.each do |supplement|
    # ISO DirectivesSupplement always uses " + " (space before)
    # CEN-style supplements (AC, A) without base_identifier use "+" (no space before)
    # Other ISO supplements with base_identifier use " + " (space before)
    if supplement.class.name&.include?("DirectivesSupplement") ||
        (supplement.class.attributes.key?(:base_identifier) && !supplement.base_identifier.nil?)
      result += " + #{supplement.to_s(lang: lang, lang_single: lang_single,
                                      with_edition: with_edition, format: format, stage_format_long: stage_format_long, with_date: with_date)}"
    else
      result += "+#{supplement.to_s(lang: lang, lang_single: lang_single,
                                    with_edition: with_edition, format: format, stage_format_long: stage_format_long, with_date: with_date)}"
    end
  end

  result
end

#to_urnObject

Generate URN for bundled identifier Flattens all components into a single URN

Example: β€œISO/IEC DIR 1:2022 + IEC SUP:2022”

β†’ "urn:iso:doc:iso-iec:dir:1:2022:iec:sup:2022"


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
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/pubid/bundled_identifier.rb', line 76

def to_urn
  # Start with base document URN components
  parts = base_document.to_urn.split(":")

  # Add each supplement's components
  supplements.each do |supplement|
    # For DirectivesSupplement: add organization and "sup" (not "dir-sup")
    if supplement.class.name&.include?("DirectivesSupplement")
      # Add organization (e.g., "IEC")
      if supplement.class.attributes.key?(:supplement_publisher) && supplement.supplement_publisher
        parts << supplement.supplement_publisher.body.downcase
      end

      # Always add "sup" for DirectivesSupplement (not "dir-sup")
      parts << "sup"

      # Add year
      parts << supplement.date.year.to_s if supplement.date
    else
      # For other supplements: use typed_stage type_code
      if supplement.typed_stage
        type_code = supplement.typed_stage.type_code
        parts << type_code.to_s unless type_code == :is
      end

      # Add supplement date
      if supplement.date
        parts << supplement.date.year.to_s
      end

      # Add supplement number if present
      if supplement.number
        parts << "v#{supplement.number.value}"
      end
    end
  end

  parts.join(":")
end

#typeObject



37
38
39
# File 'lib/pubid/bundled_identifier.rb', line 37

def type
  base_document&.type
end

#typed_stageObject



45
46
47
# File 'lib/pubid/bundled_identifier.rb', line 45

def typed_stage
  base_document&.typed_stage
end