Class: Pubid::Iso::BundledIdentifier

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

Overview

Identifier that represents a bundled identifier with base document and supplements E.g., “ISO/IEC DIR 1 + IEC SUP:2016-05” or “ISO/IEC DIR 1:2022 + IEC SUP:2022”

Constant Summary

Constants inherited from Identifier

Identifier::ISO_TYPE_MAP

Instance Method Summary collapse

Methods inherited from Identifier

#all_parts_from_kv, #all_parts_to_kv, #build_code, build_type_map, #copublishers_from_kv, #date_for, #day_from_kv, default_publisher, #emit_code, #emit_date_part, from_hash, #month_from_kv, #number_from_kv, parse, #part_from_kv, published_typed_stage, #publisher_for, #publisher_from_kv, #stage, #stage_from_kv, #stage_iteration_from_kv, #stage_iteration_to_kv, #subpart_from_kv, #type, #with_harmonized_stage, #year_from_kv

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

Constructor Details

This class inherits a constructor from Pubid::Identifier

Instance Method Details

#base_document_from_kv(model, value) ⇒ Object



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

def base_document_from_kv(model, value)
  model.base_document = ::Pubid::Iso::Identifier.from_hash(value) if value
end

#base_document_to_kv(model, doc) ⇒ Object



26
27
28
29
30
31
32
# File 'lib/pubid/iso/bundled_identifier.rb', line 26

def base_document_to_kv(model, doc)
  return unless model.base_document

  doc.add_child(Lutaml::KeyValue::DataModel::Element.new(
                  "base", model.base_document.to_hash
                ))
end

#copublishersObject



85
86
87
# File 'lib/pubid/iso/bundled_identifier.rb', line 85

def copublishers
  base_document&.copublishers
end

#copublishers_to_kv(_model, _doc) ⇒ Object



61
# File 'lib/pubid/iso/bundled_identifier.rb', line 61

def copublishers_to_kv(_model, _doc); end

#dateObject



77
78
79
# File 'lib/pubid/iso/bundled_identifier.rb', line 77

def date
  base_document&.date
end

#day_to_kv(_model, _doc) ⇒ Object



59
# File 'lib/pubid/iso/bundled_identifier.rb', line 59

def day_to_kv(_model, _doc); end

#month_to_kv(_model, _doc) ⇒ Object



58
# File 'lib/pubid/iso/bundled_identifier.rb', line 58

def month_to_kv(_model, _doc); end

#numberObject



69
70
71
# File 'lib/pubid/iso/bundled_identifier.rb', line 69

def number
  base_document&.number
end

#number_to_kv(_model, _doc) ⇒ Object

The delegated common fields are carried by base_document; don’t duplicate them at the bundle level.



54
# File 'lib/pubid/iso/bundled_identifier.rb', line 54

def number_to_kv(_model, _doc); end

#partObject



73
74
75
# File 'lib/pubid/iso/bundled_identifier.rb', line 73

def part
  base_document&.part
end

#part_to_kv(_model, _doc) ⇒ Object



55
# File 'lib/pubid/iso/bundled_identifier.rb', line 55

def part_to_kv(_model, _doc); end

#publisherObject

Delegate key attributes to base_document for easier access in tests



65
66
67
# File 'lib/pubid/iso/bundled_identifier.rb', line 65

def publisher
  base_document&.publisher
end

#publisher_to_kv(_model, _doc) ⇒ Object



60
# File 'lib/pubid/iso/bundled_identifier.rb', line 60

def publisher_to_kv(_model, _doc); end

#stage_to_kv(_model, _doc) ⇒ Object



62
# File 'lib/pubid/iso/bundled_identifier.rb', line 62

def stage_to_kv(_model, _doc); end

#subpart_to_kv(_model, _doc) ⇒ Object



56
# File 'lib/pubid/iso/bundled_identifier.rb', line 56

def subpart_to_kv(_model, _doc); end

#supplements_from_kv(model, value) ⇒ Object



46
47
48
49
50
# File 'lib/pubid/iso/bundled_identifier.rb', line 46

def supplements_from_kv(model, value)
  model.supplements = Array(value).map do |h|
    ::Pubid::Iso::Identifier.from_hash(h)
  end
end

#supplements_to_kv(model, doc) ⇒ Object



38
39
40
41
42
43
44
# File 'lib/pubid/iso/bundled_identifier.rb', line 38

def supplements_to_kv(model, doc)
  return unless model.supplements&.any?

  doc.add_child(Lutaml::KeyValue::DataModel::Element.new(
                  "supplements", model.supplements.map(&:to_hash)
                ))
end

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



89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/pubid/iso/bundled_identifier.rb', line 89

def to_s(lang: :en, lang_single: false, with_edition: false, format: nil,
stage_format_long: nil, with_date: nil)
  parts = [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)]

  # Add each supplement with "+" separator
  supplements.each do |supplement|
    supplement_str = supplement.to_supplement_s(lang: lang, lang_single: lang_single,
                                                with_edition: with_edition, format: format, stage_format_long: stage_format_long, with_date: with_date)
    parts << "+ #{supplement_str}"
  end

  parts.join(" ")
end

#to_urnObject

Generate URN for bundled identifier Format: urn:iso:doc:base_urn:supplement_urn_parts Example: urn:iso:doc:iso-iec:dir:1:2022:iec:sup:2022



107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/pubid/iso/bundled_identifier.rb', line 107

def to_urn
  # Start with base document URN (remove "urn:" prefix if exists)
  base_urn = base_document.to_urn
  base_parts = base_urn.split(":").drop(1) # Drop "urn" prefix

  # Build URN parts starting with "urn"
  urn_parts = ["urn"]

  # Add base URN parts
  urn_parts.concat(base_parts)

  # Add each supplement's URN contribution
  supplements.each do |supplement|
    sup_urn = supplement.to_urn
    if supplement.is_a?(Identifiers::DirectivesSupplement)
    # DirectivesSupplement has special URN format
    # Extract parts after "urn:iso:doc:"
    else
      # For other supplement types, add their URN parts
      # Extract relevant parts and add them
    end
    sup_parts = sup_urn.split(":").drop(3)
    urn_parts.concat(sup_parts)
  end

  urn_parts.join(":")
end

#typed_stageObject



81
82
83
# File 'lib/pubid/iso/bundled_identifier.rb', line 81

def typed_stage
  base_document&.typed_stage
end

#year_to_kv(_model, _doc) ⇒ Object



57
# File 'lib/pubid/iso/bundled_identifier.rb', line 57

def year_to_kv(_model, _doc); end