Class: Pubid::Asme::UrnGenerator

Inherits:
UrnGenerator::Base show all
Defined in:
lib/pubid/asme/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_language, #urn_namespace, #urn_number, #urn_part, #urn_publisher, #urn_subpart, #urn_type, #urn_year

Constructor Details

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

Instance Method Details

#generateObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/pubid/asme/urn_generator.rb', line 6

def generate
  parts = ["urn", "asme"]

  special_type = special_identifier_type_component
  parts << special_type if special_type

  parts << publisher_component

  if identifier.code
    parts << identifier.code.to_s
  end

  part = maybe(:part)
  if part
    p = part.to_s
    parts[-1] = "#{parts[-1]}-#{p}"
  end

  subpart = maybe(:subpart)
  if subpart
    sp = subpart.to_s
    parts[-1] = "#{parts[-1]}-#{sp}"
  end

  if identifier.draft_year
    parts << identifier.draft_year.to_s
  elsif identifier.year
    parts << identifier.year.to_s
  end

  edition = maybe(:edition)
  if edition
    e = edition.number || edition.to_s
    parts << "ed.#{e}"
  end

  if special_type != "ptc" && identifier.ptc_suffix
    parts << "ptc-suffix.#{identifier.ptc_suffix}"
  end

  if special_type != "csa" && identifier.csa_number
    parts << "csa.#{identifier.csa_number}"
  end

  if identifier.first_publisher
    parts << "pub1.#{identifier.first_publisher.to_s.downcase}"
  end

  if identifier.first_code
    parts << "code1.#{identifier.first_code}"
  end

  if identifier.second_publisher
    parts << "pub2.#{identifier.second_publisher.to_s.downcase}"
  end

  if identifier.joint_publisher
    parts << "joint.#{identifier.joint_publisher.to_s.downcase}"
  end

  if identifier.language
    parts << identifier.language.to_s.downcase
  end

  if identifier.reaffirmation
    parts << "reaff.#{identifier.reaffirmation}"
  end

  if identifier.revision_note
    parts << "revnote.#{identifier.revision_note}"
  end

  if identifier.parenthetical_revision
    parts << "prev.#{identifier.parenthetical_revision}"
  end

  languages = maybe(:languages)
  if languages&.any?
    lang_codes = languages.map(&:code).join(",")
    parts << lang_codes
  end

  parts.join(":")
end