Module: Pubid::Bipm

Extended by:
PrefixesSupport
Defined in:
lib/pubid/bipm.rb,
lib/pubid/bipm/parser.rb,
lib/pubid/bipm/builder.rb,
lib/pubid/bipm/renderer.rb,
lib/pubid/bipm/identifier.rb,
lib/pubid/bipm/urn_parser.rb,
lib/pubid/bipm/identifiers.rb,
lib/pubid/bipm/urn_generator.rb,
lib/pubid/bipm/identifiers/mep.rb,
lib/pubid/bipm/identifiers/guide.rb,
lib/pubid/bipm/identifiers/meeting.rb,
lib/pubid/bipm/identifiers/si_brochure.rb,
lib/pubid/bipm/identifiers/committee_document.rb,
lib/pubid/bipm/identifiers/metrologia_article.rb

Defined Under Namespace

Modules: Identifiers Classes: Builder, Identifier, Parser, Renderer, UrnGenerator, UrnParser

Constant Summary collapse

PREFIXES =

Leading tokens a printed BIPM identifier can start with: the 13 committee acronyms, "Metrologia" (journal), and "BIPM" (the SI Brochure). JCGM is deliberately excluded — it is owned by the separate Pubid::Jcgm flavor, so BIPM never emits pubid:jcgm:* rows. French full-name forms that lead with a type word ("Recommandation 1 du CCL …") are omitted per the "exclude ambiguous tokens" policy.

%w[
  BIPM Metrologia
  CIPM CGPM JCRB CCTF CCQM CCT CCL CCAUV CCU CCM CCEM CCPR CCRI
].freeze

Class Method Summary collapse

Methods included from PrefixesSupport

prefix_flavor_key, prefixes

Class Method Details

.all_typed_stagesArray<Pubid::Components::TypedStage>

Build typed stage index from identifier types

Returns:



56
57
58
59
60
61
62
63
64
# File 'lib/pubid/bipm.rb', line 56

def self.all_typed_stages
  @all_typed_stages ||= identifier_types.flat_map do |klass|
    if klass.const_defined?(:TYPED_STAGES)
      klass.const_get(:TYPED_STAGES)
    else
      []
    end
  end
end

.identifier_typesArray<Class>

Auto-discover all identifier types from the Identifiers namespace

Returns:

  • (Array<Class>)

    identifier classes that define a self.type Hash



43
44
45
46
47
48
49
50
51
52
# File 'lib/pubid/bipm.rb', line 43

def self.identifier_types
  @identifier_types ||= Identifiers.constants.filter_map do |const|
    klass = Identifiers.const_get(const)
    klass if klass.is_a?(Class) &&
      klass.singleton_methods(false).include?(:type) &&
      klass.type.is_a?(Hash)
  rescue NameError
    nil
  end
end

.locate_stage(abbr) ⇒ Pubid::Components::TypedStage?

Lookup: abbreviation -> typed stage

Parameters:

  • abbr (String, Symbol)

    the abbreviation to find

Returns:



76
77
78
79
80
81
# File 'lib/pubid/bipm.rb', line 76

def self.locate_stage(abbr)
  abbr_str = abbr.to_s.upcase
  all_typed_stages.find do |s|
    s.abbr.any? { |a| a.to_s.upcase == abbr_str }
  end
end

.locate_type(code) ⇒ Class?

Lookup: type code -> identifier class

Parameters:

  • code (String, Symbol)

    the type key to find

Returns:

  • (Class, nil)

    the matching identifier class



69
70
71
# File 'lib/pubid/bipm.rb', line 69

def self.locate_type(code)
  identifier_types.find { |t| t.type[:key].to_s == code.to_s }
end

.parse(identifier) ⇒ Identifier

Parse a BIPM identifier string into an identifier object.

Parameters:

  • identifier (String)

    the printed identifier

Returns:



29
30
31
32
33
34
35
# File 'lib/pubid/bipm.rb', line 29

def self.parse(identifier)
  if identifier.length > Pubid::MAX_INPUT_LENGTH
    raise ArgumentError, Pubid::INPUT_TOO_LONG_MESSAGE
  end

  Identifier.parse(identifier)
end