Class: Pubid::Api::Identifier

Inherits:
Object
  • Object
show all
Defined in:
lib/pubid/api/identifier.rb

Constant Summary collapse

TYPE_KEY_TO_KLASS =

Factory that builds an API identifier from a hash of primitives. Dispatch on ‘:type` to the matching subclass; default is Pubid::Api::Identifiers::Standard.

API identifiers have a hardcoded “API” publisher (via SingleIdentifier#publisher method) so the ‘:publisher` kwarg is silently dropped.

{
  std:      "Standard",
  rp:       "RecommendedPractice",
  spec:     "Specification",
  tr:       "TechnicalReport",
  bull:     "Bulletin",
  mpms:     "Mpms",
  cos:      "ContinuousOperationsStandard",
  publ:     "Publication",
  typeless: "TypelessStandard",
}.freeze

Class Method Summary collapse

Class Method Details

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



40
41
42
43
# File 'lib/pubid/api/identifier.rb', line 40

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

.parse(input) ⇒ Object



11
12
13
14
15
16
17
18
19
# File 'lib/pubid/api/identifier.rb', line 11

def self.parse(input)
  # Filter out comments
  return nil if input.start_with?("#")

  tree = Parser.new.parse(input)
  Builder.new.build(tree)
rescue Parslet::ParseFailed => e
  raise e
end