Class: Pubid::Iho::Identifiers::Base

Inherits:
Pubid::Identifier show all
Includes:
Pubid::Iho::Identifier
Defined in:
lib/pubid/iho/identifiers/base.rb

Overview

Base class for all IHO identifiers.

IHO identifiers have the form:

IHO {S|P|M|B|C}-{number}[ Ap. {appendix}][ Part {part}][ Annex {annex}][ Suppl {supplement}][ {version}]

The leading IHO publisher prefix is optional on input but always emitted on output.

Constant Summary collapse

IHO_TYPE_MAP =

Polymorphic type map for lutaml::Model key_value serialization: maps each subclass’s polymorphic_name to its class name so ‘from_hash` can re-instantiate the concrete type from `_type`.

{
  "pubid:iho:standard"        => "Pubid::Iho::Identifiers::Standard",
  "pubid:iho:publication"     => "Pubid::Iho::Identifiers::Publication",
  "pubid:iho:miscellaneous"   => "Pubid::Iho::Identifiers::Miscellaneous",
  "pubid:iho:bibliographic"   => "Pubid::Iho::Identifiers::Bibliographic",
  "pubid:iho:circular-letter" => "Pubid::Iho::Identifiers::CircularLetter",
}.freeze

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Pubid::IdentifierFacade

#from_hash, #polymorphic_type_map

Methods inherited from Pubid::Identifier

#base_identifier, #eql?, #exclude, #hash, #initialize, #mr_number, #mr_number_with_part, #mr_part, #mr_publisher, #mr_type, #mr_year, #new_edition_of?, polymorphic_name, #render, #resolve_urn_generator, #root, #to_mr_string, #to_supplement_s, #to_urn, #urn_supplement_type, #urn_type_code, #year

Constructor Details

This class inherits a constructor from Pubid::Identifier

Class Method Details

.from_hash(data, options = {}) ⇒ Object

Re-instantiate the concrete subclass from ‘_type`. lutaml’s polymorphic_map only validates ‘_type` on key_value deserialization; without this routing `from_hash` returns a bare Base (no #type, which breaks #to_s). Mirrors Pubid::Iso::Identifier.from_hash.



59
60
61
62
63
64
65
66
# File 'lib/pubid/iho/identifiers/base.rb', line 59

def self.from_hash(data, options = {})
  klass_name = IHO_TYPE_MAP[data["_type"] || data[:_type]]
  if klass_name
    klass = Object.const_get(klass_name)
    return klass.from_hash(data, options) unless klass == self
  end
  super
end

.parse(string) ⇒ Object



68
69
70
# File 'lib/pubid/iho/identifiers/base.rb', line 68

def self.parse(string)
  Iho::Identifier.parse(string)
end

Instance Method Details

#to_sString

Render the identifier as a string in canonical IHO form.

Returns:

  • (String)


74
75
76
# File 'lib/pubid/iho/identifiers/base.rb', line 74

def to_s
  render(format: :human)
end