Module: Pubid::CenCenelec::Identifier

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

Class Method Summary collapse

Class Method Details

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

Factory mirroring pubid 1.x’s ‘Pubid::Cen::Identifier.create` API. Dispatches via Scheme’s IDENTIFIER_CLASS_MAP and TYPED_STAGES_REGISTRY. Default is EuropeanNorm.



19
20
21
22
23
24
25
# File 'lib/pubid/cen_cenelec/identifier.rb', line 19

def self.create(type: nil, stage: nil, **opts)
  klass = resolve_create_class(type: type, stage: stage)
  attrs = ::Pubid::Components::Factory.from_hash(opts)
  ts = resolve_create_typed_stage(klass, stage)
  attrs[:typed_stage] = ts if ts
  klass.new(**attrs)
end

.parse(identifier) ⇒ Object



8
9
10
11
12
13
14
# File 'lib/pubid/cen_cenelec/identifier.rb', line 8

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