Class: Pubid::Api::UrnParser

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

Overview

Parses API URNs back into identifiers.

UrnGenerator emits:

urn:api:{publisher}:{number}[-{part}]:{year}

where slot is the publisher (default “api”), slot is the number with optional ‘-part` suffix, slot is the optional year.

Examples:

  • urn:api:api:1104 → API STD 1104

  • urn:api:api:1104-1:2020 → API STD 1104-1:2020

Instance Method Summary collapse

Methods inherited from UrnParser::Base

parse

Instance Method Details

#parse_urn(urn) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/pubid/api/urn_parser.rb', line 16

def parse_urn(urn)
  body = strip_namespace(urn)
  parts = split_parts(body)

  _type, number = parts
  idx = 2
  part = nil
  if parts[idx]&.start_with?("-")
    part = parts[idx]
    idx += 1
  end
  year = parts[idx]

  text = "API STD #{number}#{part}"
  text += ":#{year}" if year
  flavor_parse(text)
end