Module: Pubid::Api

Defined in:
lib/pubid/api.rb,
lib/pubid/api/parser.rb,
lib/pubid/api/builder.rb,
lib/pubid/api/renderer.rb,
lib/pubid/api/identifier.rb,
lib/pubid/api/urn_parser.rb,
lib/pubid/api/identifiers.rb,
lib/pubid/api/urn_generator.rb,
lib/pubid/api/components/code.rb,
lib/pubid/api/identifiers/base.rb,
lib/pubid/api/identifiers/mpms.rb,
lib/pubid/api/single_identifier.rb,
lib/pubid/api/identifiers/bulletin.rb,
lib/pubid/api/identifiers/standard.rb,
lib/pubid/api/identifiers/publication.rb,
lib/pubid/api/identifiers/specification.rb,
lib/pubid/api/identifiers/technical_report.rb,
lib/pubid/api/identifiers/typeless_standard.rb,
lib/pubid/api/identifiers/recommended_practice.rb,
lib/pubid/api/identifiers/continuous_operations_standard.rb

Defined Under Namespace

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

Class Method Summary collapse

Class Method Details

.all_typed_stagesArray<Pubid::Components::TypedStage>

Build typed stage index from identifier types

Returns:



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

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 (Pubid::Identifier subclasses)



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

def self.identifier_types
  @identifier_types ||= Identifiers.constants
    .filter_map { |c| begin; Identifiers.const_get(c); rescue NameError; nil; end }
    .select { |c| c.is_a?(Class) && c < Pubid::Identifier }
    .reject { |c| c.name&.split("::")&.last == "Base" }
end

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

Lookup: abbreviation -> typed stage

Parameters:

  • abbr (String, Symbol)

    the abbreviation to find

Returns:



51
52
53
54
# File 'lib/pubid/api.rb', line 51

def self.locate_stage(abbr)
  abbr_str = abbr.to_s.upcase
  all_typed_stages.find { |s| s.abbr.any? { |a| a.to_s.upcase == abbr_str } }
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



42
43
44
45
46
# File 'lib/pubid/api.rb', line 42

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

.parse(input) ⇒ Object



14
15
16
# File 'lib/pubid/api.rb', line 14

def self.parse(input)
  Identifier.parse(input)
end