Class: Pubid::Iso::Identifiers::DirectivesSupplement

Inherits:
SupplementIdentifier show all
Defined in:
lib/pubid/iso/identifiers/directives_supplement.rb

Constant Summary collapse

TYPED_STAGES =
[
  ::Pubid::Components::TypedStage.new(
    code: :pubdirsup,
    stage_code: :published,
    type_code: :"dir-sup",
    abbr: ["DIR SUP", "SUP", "Supplement"],
    name: "Directives Supplement",
    harmonized_stages: %w[60.00 60.60],
  ),
].freeze

Constants inherited from Pubid::Iso::Identifier

Pubid::Iso::Identifier::ISO_TYPE_MAP

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Pubid::Iso::Identifier

#all_parts_from_kv, #all_parts_to_kv, #build_code, build_type_map, #copublishers_from_kv, #date_for, #day_from_kv, #day_to_kv, default_publisher, #emit_code, #emit_date_part, from_hash, #month_from_kv, #month_to_kv, #number_from_kv, #number_to_kv, parse, #part_from_kv, #part_to_kv, published_typed_stage, #publisher_for, #publisher_from_kv, #publisher_to_kv, #stage, #stage_from_kv, #stage_iteration_from_kv, #stage_iteration_to_kv, #stage_to_kv, #subpart_from_kv, #subpart_to_kv, #type, #with_harmonized_stage, #year_from_kv, #year_to_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, #urn_supplement_type, #urn_type_code, #year

Constructor Details

This class inherits a constructor from Pubid::Identifier

Class Method Details

.typeObject



56
57
58
59
# File 'lib/pubid/iso/identifiers/directives_supplement.rb', line 56

def self.type
  { key: :"dir-sup",
    web: :directives_supplement, title: "Directives Supplement", short: "SUP" }
end

Instance Method Details

#copublishersObject

Delegate base identifier attributes for easier access



37
38
39
# File 'lib/pubid/iso/identifiers/directives_supplement.rb', line 37

def copublishers
  base_identifier&.copublishers
end

#copublishers_to_kv(_model, _doc) ⇒ Object

copublishers here is the base’s (delegated), redundant with the nested base; don’t duplicate it at the supplement level.



34
# File 'lib/pubid/iso/identifiers/directives_supplement.rb', line 34

def copublishers_to_kv(_model, _doc); end

#publisherObject



41
42
43
# File 'lib/pubid/iso/identifiers/directives_supplement.rb', line 41

def publisher
  base_identifier&.publisher
end

#supplement_publisher_from_kv(model, value) ⇒ Object



28
29
30
# File 'lib/pubid/iso/identifiers/directives_supplement.rb', line 28

def supplement_publisher_from_kv(model, value)
  model.supplement_publisher = ::Pubid::Components::Publisher.new(body: value.to_s)
end

#supplement_publisher_to_kv(model, doc) ⇒ Object



19
20
21
22
23
24
25
26
# File 'lib/pubid/iso/identifiers/directives_supplement.rb', line 19

def supplement_publisher_to_kv(model, doc)
  body = model.supplement_publisher&.body
  return if body.nil? || body.to_s.empty?

  doc.add_child(
    Lutaml::KeyValue::DataModel::Element.new("publisher", body.to_s),
  )
end

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

render(identifier.base_identifier) +

" #{identifier.publisher.body}" +
" #{identifier.stage.abbr}" +
(identifier.date ? ":#{identifier.date.year}" : "")

end



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/pubid/iso/identifiers/directives_supplement.rb', line 70

def to_s(lang: :en, lang_single: false, with_edition: false,
format: nil, stage_format_long: nil, with_date: nil)
  if base_identifier
    # Full rendering with base identifier
    [
      base_identifier.to_s(lang: lang, lang_single: lang_single,
                           with_edition: with_edition, format: format, stage_format_long: stage_format_long, with_date: with_date),
      " #{supplement_publisher.render}",
      " SUP", # Always render as "SUP" even though typed_stage.abbreviation is "DIR SUP"
      (date ? ":#{date.render}" : ""),
      (edition ? " Edition #{edition.value}" : ""),
    ].join
  else
    # Simplified rendering for bundled identifiers (just the supplement part)
    to_supplement_s(lang: lang, lang_single: lang_single)
  end
end

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

Render just the supplement part (for use in bundled identifiers)



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

def to_supplement_s(lang: :en, lang_single: false, with_edition: false,
format: nil, stage_format_long: nil, with_date: nil)
  date_str = if date
               month_part = date.month ? "-#{date.month}" : ""
               ":#{date.render}#{month_part}"
             else
               ""
             end

  [
    supplement_publisher.render,
    " SUP",
    date_str,
  ].join
end

#to_urnObject

DirectivesSupplement use urn:iso:doc scheme (not urn:iso:std) Format: urn:iso:doc:base_urn_parts:Pubid::Identifier#year">jtc:X:sup[:edition]



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
134
135
136
137
138
139
140
141
142
143
144
# File 'lib/pubid/iso/identifiers/directives_supplement.rb', line 107

def to_urn
  urn_ctx = Rendering::RenderingContext.urn

  # If this is a standalone supplement (no base_identifier), build URN directly
  unless base_identifier
    parts = ["urn", "iso", "doc"]
    parts << supplement_publisher.render(context: urn_ctx) if supplement_publisher
    parts << "sup"
    parts << date.render(context: urn_ctx) if date
    parts << edition.render(context: urn_ctx) if edition&.number
    return parts.join(":")
  end

  # Start with base identifier's URN parts (it will use urn:iso:doc scheme)
  base_urn = base_identifier.to_urn

  # Handle JTC pattern specially
  if supplement_publisher&.body&.match?(/^JTC\s+(\d+)$/i)
    # Extract JTC number: "JTC 1" -> ["jtc", "1"]
    jtc_parts = supplement_publisher.render(context: urn_ctx).split
    # Insert JTC parts before "sup"
    parts = base_urn.split(":")
    parts.concat(jtc_parts) # Add "jtc" and "1"
    parts << "sup"
  else
    # Normal supplement
    parts = [base_urn, "sup"]
    parts << supplement_publisher.render(context: urn_ctx) if supplement_publisher
  end

  # Year (if present)
  parts << date.render(context: urn_ctx) if date

  # Edition (if present)
  parts << edition.render(context: urn_ctx) if edition&.number

  parts.join(":")
end