Class: Pubid::UrnGenerator::Base
- Inherits:
-
Object
- Object
- Pubid::UrnGenerator::Base
show all
- Defined in:
- lib/pubid/urn_generator/base.rb
Overview
Base class for all flavor-specific URN generators. Provides template methods for common URN parts. Flavors subclass and override only what differs.
Direct Known Subclasses
Amca::UrnGenerator, Ansi::UrnGenerator, Api::UrnGenerator, Ashrae::UrnGenerator, Asme::UrnGenerator, Astm::UrnGenerator, Bsi::UrnGenerator, Ccsds::UrnGenerator, CenCenelec::UrnGenerator, Cie::UrnGenerator, Csa::UrnGenerator, Etsi::UrnGenerator, Idf::UrnGenerator, Iec::UrnGenerator, Ieee::UrnGenerator, Itu::UrnGenerator, Jcgm::UrnGenerator, Jis::UrnGenerator, Nist::UrnGenerator, Oiml::UrnGenerator, Plateau::UrnGenerator, Sae::UrnGenerator
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(identifier) ⇒ Base
Returns a new instance of Base.
11
12
13
|
# File 'lib/pubid/urn_generator/base.rb', line 11
def initialize(identifier)
@identifier = identifier
end
|
Instance Attribute Details
#identifier ⇒ Object
Returns the value of attribute identifier.
9
10
11
|
# File 'lib/pubid/urn_generator/base.rb', line 9
def identifier
@identifier
end
|
Instance Method Details
#generate ⇒ Object
15
16
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/pubid/urn_generator/base.rb', line 15
def generate
parts = ["urn", urn_namespace]
parts << urn_publisher if urn_publisher
parts << urn_type if urn_type
parts << urn_number if urn_number
parts << urn_part if urn_part
parts << urn_subpart if urn_subpart
parts << urn_year if urn_year
parts << urn_edition if urn_edition
parts << urn_language if urn_language
parts.join(":")
end
|
#maybe(method_name) ⇒ Object
96
97
98
99
100
|
# File 'lib/pubid/urn_generator/base.rb', line 96
def maybe(method_name)
return nil unless identifier.class.attributes.key?(method_name)
identifier.public_send(method_name)
end
|
#urn_edition ⇒ Object
79
80
81
82
83
84
85
86
87
|
# File 'lib/pubid/urn_generator/base.rb', line 79
def urn_edition
ed = maybe(:edition)
return nil unless ed
num = ed.is_a?(Components::Edition) ? ed.number : ed
return nil unless num
"ed.#{num}"
end
|
#urn_language ⇒ Object
89
90
91
92
93
94
|
# File 'lib/pubid/urn_generator/base.rb', line 89
def urn_language
langs = maybe(:languages)
return nil unless langs&.any?
langs.map(&:code).join(",")
end
|
#urn_namespace ⇒ Object
Template methods — override in subclasses
30
31
32
|
# File 'lib/pubid/urn_generator/base.rb', line 30
def urn_namespace
flavor_name.downcase
end
|
#urn_number ⇒ Object
45
46
47
48
49
50
|
# File 'lib/pubid/urn_generator/base.rb', line 45
def urn_number
val = maybe(:number) || maybe(:code)
return nil unless val
val.is_a?(Components::Code) ? val.value.to_s : val.to_s
end
|
#urn_part ⇒ Object
52
53
54
55
56
57
|
# File 'lib/pubid/urn_generator/base.rb', line 52
def urn_part
val = maybe(:part)
return nil unless val
"-#{val.is_a?(Components::Code) ? val.value : val}"
end
|
#urn_publisher ⇒ Object
34
35
36
37
38
39
|
# File 'lib/pubid/urn_generator/base.rb', line 34
def urn_publisher
pub = maybe(:publisher)
return nil unless pub
pub.to_s.downcase
end
|
#urn_subpart ⇒ Object
59
60
61
62
63
64
|
# File 'lib/pubid/urn_generator/base.rb', line 59
def urn_subpart
val = maybe(:subpart)
return nil unless val
"-#{val.is_a?(Components::Code) ? val.value : val}"
end
|
#urn_type ⇒ Object
41
42
43
|
# File 'lib/pubid/urn_generator/base.rb', line 41
def urn_type
nil
end
|
#urn_year ⇒ Object
66
67
68
69
70
71
72
73
74
75
76
77
|
# File 'lib/pubid/urn_generator/base.rb', line 66
def urn_year
date = maybe(:date)
if date
year = date.is_a?(Components::Date) ? date.year : date.to_s
return year.to_s if year
end
if maybe(:year)
return identifier.year.to_s
end
nil
end
|