Class: Pubid::Iec::UrnParser
- Inherits:
-
Object
- Object
- Pubid::Iec::UrnParser
- Defined in:
- lib/pubid/iec/urn_parser.rb
Overview
Parses IEC URNs in the legacy positional format (relaton-data-iec ground truth):
urn:iec:std:{publisher}:{number}[-{part}]:{date}:{type}:{deliverable}:{language}[:{adjuncts}]
Examples:
- urn:iec:std:iec:60050:2011:
- urn:iec:std:iec:62547:2013:tr
-
(type after date)
-
urn:iec:std:iec:60050-102:2007:::::amd:1:2017
-
urn:iec:std:iec:60034-16-3:1996:ts::fr (deliverable empty, language fr)
-
urn:iec:std:iec:80000:::ser (all-parts series)
This is a port of relaton-iec’s urn_to_code: the positional fields are reassembled into a code string which is then run through the text parser (Identifier.parse), so there is a single source of truth for building the identifier object.
Class Method Summary collapse
-
.parse(urn) ⇒ Identifier
Parse IEC URN string.
Instance Method Summary collapse
-
#parse_urn(urn) ⇒ Identifier
Parse URN string into identifier.
Class Method Details
.parse(urn) ⇒ Identifier
Parse IEC URN string
25 26 27 |
# File 'lib/pubid/iec/urn_parser.rb', line 25 def self.parse(urn) new.parse_urn(urn) end |
Instance Method Details
#parse_urn(urn) ⇒ Identifier
Parse URN string into identifier
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/pubid/iec/urn_parser.rb', line 32 def parse_urn(urn) unless urn.start_with?("urn:iec:std:") raise Errors::ParseError, "Invalid IEC URN: #{urn}" end code, lang, all_parts = urn_to_code(urn) raise Errors::ParseError, "Invalid IEC URN: #{urn}" unless code id = Pubid::Iec::Identifier.parse(code) id.all_parts = true if all_parts && id.respond_to?(:all_parts=) if lang && !lang.empty? && id.respond_to?(:languages=) id.languages = [::Pubid::Components::Language.new(code: lang)] end id end |