Class: Pubid::Easc::UrnGenerator
- Inherits:
-
Object
- Object
- Pubid::Easc::UrnGenerator
- Defined in:
- lib/pubid/easc/urn_generator.rb
Overview
Generates URN strings for EASC identifiers.
Format:
urn:easc:<series>[:<variant>]:<number>[:<year>]
Examples:
urn:easc:pmg:3:2025
urn:easc:pmg:v:31:2001
urn:easc:rmg:151:2025
Instance Attribute Summary collapse
-
#identifier ⇒ Object
readonly
Returns the value of attribute identifier.
Instance Method Summary collapse
- #generate ⇒ Object
-
#initialize(identifier) ⇒ UrnGenerator
constructor
A new instance of UrnGenerator.
Constructor Details
#initialize(identifier) ⇒ UrnGenerator
Returns a new instance of UrnGenerator.
17 18 19 |
# File 'lib/pubid/easc/urn_generator.rb', line 17 def initialize(identifier) @identifier = identifier end |
Instance Attribute Details
#identifier ⇒ Object (readonly)
Returns the value of attribute identifier.
15 16 17 |
# File 'lib/pubid/easc/urn_generator.rb', line 15 def identifier @identifier end |
Instance Method Details
#generate ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/pubid/easc/urn_generator.rb', line 21 def generate unless identifier.is_a?(Identifiers::Pmg) || identifier.is_a?(Identifiers::Rmg) raise ArgumentError, "Unknown EASC identifier class: #{identifier.class}" end parts = ["urn:easc", series_lower] parts << variant_lower if identifier.variant parts << identifier.number.to_s parts << identifier.year.to_s if identifier.year parts.join(":") end |