Class: Pubid::Iho::UrnParser

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

Overview

Parses IHO URNs back into identifiers.

UrnGenerator emits:

urn:iho:{type-lower}:{number}[:{part-kind}.{part}]:{version}

type-lower is the lowercase series letter (s, p, m, b, c). part-kind is the lowercase part label (part, ap, annex, suppl). version is the dotted version string.

Examples:

  • urn:iho:s:44:5.0.0 → IHO S-44 5.0.0

  • urn:iho:s:100:part.4a:1.0.0 → IHO S-100 Part 4a 1.0.0

  • urn:iho:s:65:ap.A:1.0.0 → IHO S-65 Ap. A 1.0.0

Constant Summary collapse

PART_LABELS =
{
  "part" => "Part",
  "ap" => "Ap.",
  "annex" => "Annex",
  "suppl" => "Suppl",
}.freeze

Instance Method Summary collapse

Methods inherited from UrnParser::Base

parse

Instance Method Details

#parse_urn(urn) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/pubid/iho/urn_parser.rb', line 26

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

  type_token = parts.fetch(0).upcase
  number = parts.fetch(1)
  idx = 2
  part_label = nil
  if parts[idx] && part_kind?(parts[idx])
    kind, value = parts[idx].split(".", 2)
    label = PART_LABELS.fetch(kind.downcase) { kind.capitalize }
    part_label = "#{label} #{value}"
    idx += 1
  end
  version = parts[idx]

  text = "IHO #{type_token}-#{number}"
  text += " #{part_label}" if part_label
  text += " #{version}" if version
  flavor_parse(text)
end