Module: Pubid::Iho::Identifier

Defined in:
lib/pubid/iho/identifier.rb

Overview

Entry point for parsing IHO identifiers.

Class Method Summary collapse

Class Method Details

.create(type: nil, **opts) ⇒ Object

Factory that builds an IHO identifier from a hash of primitives.

IHO identifiers are simpler than ISO/IEC: attributes are plain strings (no Component wrapping), so coercion just calls #to_s.

Dispatch:

* `type:` accepts the type key (`:standard`, `:publication`,
  `:miscellaneous`, `:bibliographic`, `:circular_letter`) or
  the IHO series letter (`"S"`, `"P"`, `"M"`, `"B"`, `"C"`).
* Default is {Identifiers::Standard}.

Parameters:

  • type (Symbol, String, nil) (defaults to: nil)
  • opts (Hash)

    :publisher (default “IHO”), :code, :appendix, :part, :annex, :supplement, :version



32
33
34
35
# File 'lib/pubid/iho/identifier.rb', line 32

def self.create(type: nil, **opts)
  klass = resolve_create_class(type)
  klass.new(**coerce_create_attrs(opts))
end

.parse(identifier) ⇒ Pubid::Iho::Identifiers::Base

Parse an IHO identifier string into an identifier object

Parameters:

  • identifier (String)

    The IHO identifier string to parse

Returns:

Raises:

  • (Parslet::ParseFailed)

    If parsing fails



11
12
13
14
15
16
# File 'lib/pubid/iho/identifier.rb', line 11

def self.parse(identifier)
  parsed = Parser.parse(identifier)
  Builder.build(parsed)
rescue Parslet::ParseFailed => e
  raise "Failed to parse IHO identifier '#{identifier}': #{e.message}"
end