Class: Pubid::Calconnect::UrnParser

Inherits:
UrnParser::Base show all
Defined in:
lib/pubid/calconnect/urn_parser.rb

Overview

Parses CalConnect URNs back into identifiers.

UrnGenerator emits: urn:calconnect:: urn:calconnect:18011:2018 → CC 18011:2018 urn:calconnect:DIR:10006:2019 → CC/DIR 10006:2019 urn:calconnect:WD:51017:2024-07-23 → CC/WD 51017:2024-07-23

The date segment (year or full "YYYY-MM-DD") never contains a colon, so it is a single trailing part; the number precedes it, and an optional series precedes the number.

This positional pop assumes a dated URN (the form UrnGenerator emits for a full id). A partial (date-less) reference has no round-trippable URN — see UrnGenerator — so this parser is only guaranteed for URNs produced from a full id; a date-less URN misaligns the pops and will not parse.

Instance Method Summary collapse

Methods inherited from UrnParser::Base

parse

Instance Method Details

#parse_urn(urn) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/pubid/calconnect/urn_parser.rb', line 21

def parse_urn(urn)
  parts = split_parts(strip_namespace(urn))
  date = parts.pop
  number = parts.pop
  series = parts.pop

  text = +"CC"
  text << "/#{series}" if series
  text << " #{number}:#{date}"
  flavor_parse(text)
end