Class: Pubid::Astm::UrnGenerator

Inherits:
UrnGenerator::Base show all
Defined in:
lib/pubid/astm/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
# File 'lib/pubid/astm/urn_generator.rb', line 6

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

  if identifier.type
    type = identifier.type&.abbr || identifier.type.to_s
    parts << type.to_s.downcase
  else
    parts << "std"
  end

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

  number = maybe(:number)
  if number
    num = number.to_s
    parts << num
  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

  year = extract_year
  parts << year if year

  sub_year = maybe(:sub_year)
  parts << sub_year.to_s if sub_year

  reapproval = maybe(:reapproval)
  parts << "reapp.#{reapproval}" if reapproval

  edition = maybe(:edition)
  parts << "e#{edition}" if edition

  wip = maybe(:work_in_progress)
  parts << "wip" if wip

  wk = maybe(:wk)
  parts << "wk.#{wk}" if wk

  pub = identifier.publisher
  if pub
    p = pub.to_s
    parts[1] = p.to_s.downcase
  end

  copubs = maybe(:copublishers)
  if copubs&.any?
    cp = copubs.map(&:to_s)
    parts[1] = "#{parts[1]}-#{cp.join('-').downcase}"
  end

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

  parts.join(":")
end