Class: Pubid::Csa::UrnParser

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

Overview

Parses CSA URNs back into identifiers.

UrnGenerator emits:

urn:csa:{publisher}:{code}:{year}:format.{format}

The trailing ‘format.X` token records the year-separator style used in the human-readable form (`dash` for `-`, `colon` for `:`).

Examples:

  • urn:csa:csa:Z240.2.1:16:format.dash → CSA Z240.2.1-16

Constant Summary collapse

YEAR_SEPARATOR =
{ "dash" => "-", "colon" => ":" }.freeze

Instance Method Summary collapse

Methods inherited from UrnParser::Base

parse

Instance Method Details

#parse_urn(urn) ⇒ Object



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

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

  format_token = parts.find { |p| p.start_with?("format.") }
  separator = YEAR_SEPARATOR.fetch(format_token&.split(".")&.last, "-")

  payload = parts.reject { |p| p.start_with?("format.") }
  _publisher, code, year = payload
  text = "CSA #{code}"
  text += "#{separator}#{year}" if year
  flavor_parse(text)
end