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

Constructor Details

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

Instance Method Details

#generateObject



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/pubid/oiml/urn_generator.rb', line 38

def generate
  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



30
31
32
# File 'lib/pubid/oiml/urn_generator.rb', line 30

def urn_iteration
  identifier.iteration&.to_s
end

#urn_languageObject



34
35
36
# File 'lib/pubid/oiml/urn_generator.rb', line 34

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



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

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

#urn_yearObject



18
19
20
21
22
23
24
# File 'lib/pubid/oiml/urn_generator.rb', line 18

def urn_year
  if identifier.date&.year
    return identifier.date.year.to_s
  end

  nil
end