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

build_type_map, parse

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

Constructor Details

This class inherits a constructor from Pubid::Identifier

Class Method Details

.typeObject



30
31
32
# File 'lib/pubid/iso/identifiers/directives_supplement.rb', line 30

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

Instance Method Details

#copublishersObject

Delegate base identifier attributes for easier access



11
12
13
# File 'lib/pubid/iso/identifiers/directives_supplement.rb', line 11

def copublishers
  base_identifier&.copublishers
end

#publisherObject



15
16
17
# File 'lib/pubid/iso/identifiers/directives_supplement.rb', line 15

def publisher
  base_identifier&.publisher
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



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/pubid/iso/identifiers/directives_supplement.rb', line 43

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.body}",
      " SUP", # Always render as "SUP" even though typed_stage.abbreviation is "DIR SUP"
      (date ? ":#{date.year}" : ""),
      (edition ? " Edition #{edition.number.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)



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/pubid/iso/identifiers/directives_supplement.rb', line 62

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.year}#{month_part}"
             else
               ""
             end

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

#to_urnObject

DirectivesSupplement use urn:iso:doc scheme (not urn:iso:std) Format: urn:iso:doc:base_urn_parts:jtc:X:sup[:edition]



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
115
# File 'lib/pubid/iso/identifiers/directives_supplement.rb', line 80

def to_urn
  # If this is a standalone supplement (no base_identifier), build URN directly
  unless base_identifier
    parts = ["urn", "iso", "doc"]
    parts << supplement_publisher.body.downcase if supplement_publisher
    parts << "sup"
    parts << date.year.to_s if date
    parts << "ed-#{edition.number}" 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.body.downcase.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.body.downcase if supplement_publisher
  end

  # Year (if present)
  parts << date.year.to_s if date

  # Edition (if present)
  parts << "ed-#{edition.number}" if edition&.number

  parts.join(":")
end