Module: Pubid::Bsi::Identifier

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

Class Method Summary collapse

Class Method Details

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

Factory mirroring pubid 1.x’s ‘Pubid::Bsi::Identifier.create` API. Dispatches via Scheme’s IDENTIFIER_CLASS_MAP and TYPED_STAGES_REGISTRY; default subclass is BritishStandard.

BSI’s renderer requires BSI-namespaced Component subclasses (‘Bsi::Components::*`), so coercion is inlined rather than reusing Components::Factory.



33
34
35
36
37
38
39
# File 'lib/pubid/bsi/identifier.rb', line 33

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

.parse(string) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/pubid/bsi/identifier.rb', line 6

def self.parse(string)
  # Delegate to IEC for bare IEC identifiers
  # This handles IEC-specific features like VAP suffixes (CSV, RLV, etc.)
  # and consolidated supplements (+AMD1:2001)
  if string.match?(/\bIEC\b/) &&
      (string.match?(/\s+(CSV|CMV|RLV|SER|EXV|PAC|PRV)\b/) ||
       string.match?(/\+AMD\d+:/) ||
       string.match?(/\+COR\d+:/))
    return Pubid::Iec.parse(string)
  end

  parser = Parser.new
  scheme = Scheme.new

  parsed = parser.parse(string)
  Builder.build(parsed, scheme)
rescue Parslet::ParseFailed => e
  raise StandardError, "Failed to parse '#{string}': #{e.message}"
end