Class: Pubid::UrnParser::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/pubid/urn_parser/base.rb

Overview

Base class for flavor-specific URN parsers.

A UrnParser inverts its sibling UrnGenerator: it consumes the URN emitted by {Flavor::UrnGenerator} and rebuilds an Identifier. The preferred strategy is to reconstruct a human-readable identifier string from the URN fields and delegate to the flavor’s text parser —this keeps parsing logic in one place (the flavor’s text parser).

Subclasses MUST override #parse_urn. They typically use #strip_namespace and #flavor_parse helpers and may pass through #build_from_parts for the common ‘urn:flavor:publisher:type: number:year` shape.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.parse(urn) ⇒ Pubid::Identifier

Parse a URN string into an Identifier.

Parameters:

  • urn (String)

Returns:



21
22
23
# File 'lib/pubid/urn_parser/base.rb', line 21

def self.parse(urn)
  new.parse_urn(urn)
end

Instance Method Details

#parse_urn(_urn) ⇒ Object

Subclasses override.

Raises:

  • (NotImplementedError)


27
28
29
30
# File 'lib/pubid/urn_parser/base.rb', line 27

def parse_urn(_urn)
  raise NotImplementedError,
        "#{self.class} must implement #parse_urn"
end