Class: Pubid::Oiml::UrnGenerator

Inherits:
UrnGenerator::Base show all
Defined in:
lib/pubid/oiml/urn_generator.rb

Instance Attribute Summary

Attributes inherited from UrnGenerator::Base

#identifier

Instance Method Summary collapse

Methods inherited from UrnGenerator::Base

#initialize, #maybe, #urn_edition, #urn_namespace, #urn_part, #urn_publisher, #urn_subpart, #urn_year

Constructor Details

This class inherits a constructor from Pubid::UrnGenerator::Base

Instance Method Details

#bulletin_locatorObject

Structured locator "YYYY-II-SS" (or "YYYY-II" / "YYYY") for a Bulletin. Built directly from the date year and the issue/sequence attributes so the URN is identical regardless of whether the input was the structured or citation form.



70
71
72
73
74
75
# File 'lib/pubid/oiml/urn_generator.rb', line 70

def bulletin_locator
  locator = identifier.date.year.to_s
  locator += "-#{identifier.issue}" if identifier.issue
  locator += "-#{identifier.sequence}" if identifier.sequence
  locator
end

#generateObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/pubid/oiml/urn_generator.rb', line 30

def generate
  # Bulletin issues carry no code; the (year, issue, sequence) tuple
  # is the locator. URNs are canonical regardless of how the input was
  # formatted, so we always emit the structured YYYY-II-SS form even
  # when the identifier was parsed from a citation string.
  if identifier.is_a?(Identifiers::Bulletin)
    parts = ["urn", "oiml", "bulletin"]
    parts << bulletin_locator if identifier.date&.present?
    parts << urn_language if urn_language
    return parts.join(":")
  end

  parts = ["urn", "oiml"]
  parts << urn_type
  parts << urn_number if urn_number
  parts << urn_year if urn_year
  parts << urn_stage if urn_stage
  parts << urn_iteration if urn_iteration
  parts << urn_language if urn_language

  parts[1] = identifier.publisher.to_s.downcase if identifier.publisher

  if identifier.is_a?(SupplementIdentifier)
    if identifier.typed_stage
      supp_type = identifier.typed_stage.type_code.to_s
      parts << supp_type if supp_type
    end

    if identifier.number
      parts << identifier.number.to_s
    end
  end

  parts.join(":")
end

#urn_iterationObject



22
23
24
# File 'lib/pubid/oiml/urn_generator.rb', line 22

def urn_iteration
  identifier.iteration&.to_s
end

#urn_languageObject



26
27
28
# File 'lib/pubid/oiml/urn_generator.rb', line 26

def urn_language
  identifier.language&.to_s&.downcase
end

#urn_numberObject



12
13
14
15
16
# File 'lib/pubid/oiml/urn_generator.rb', line 12

def urn_number
  return nil unless identifier.code

  identifier.code.to_s
end

#urn_stageObject



18
19
20
# File 'lib/pubid/oiml/urn_generator.rb', line 18

def urn_stage
  identifier.stage&.to_s&.downcase
end

#urn_typeObject



6
7
8
9
10
# File 'lib/pubid/oiml/urn_generator.rb', line 6

def urn_type
  return "r" unless identifier.type

  identifier.type.to_s.downcase
end