Module: Pubid::Iala

Extended by:
PrefixesSupport
Defined in:
lib/pubid/iala.rb,
lib/pubid/iala/parser.rb,
lib/pubid/iala/builder.rb,
lib/pubid/iala/renderer.rb,
lib/pubid/iala/identifier.rb,
lib/pubid/iala/urn_parser.rb,
lib/pubid/iala/identifiers.rb,
lib/pubid/iala/urn_generator.rb,
lib/pubid/iala/identifiers/base.rb,
lib/pubid/iala/identifiers/annex.rb,
lib/pubid/iala/identifiers/advice.rb,
lib/pubid/iala/identifiers/letter.rb,
lib/pubid/iala/identifiers/manual.rb,
lib/pubid/iala/identifiers/report.rb,
lib/pubid/iala/identifiers/standard.rb,
lib/pubid/iala/identifiers/guideline.rb,
lib/pubid/iala/identifiers/resolution.rb,
lib/pubid/iala/identifiers/model_course.rb,
lib/pubid/iala/identifiers/recommendation.rb,
lib/pubid/iala/identifiers/general_assembly.rb

Defined Under Namespace

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

Constant Summary collapse

PREFIXES =

Sole IALA publisher token (see the parser's publisher rule).

["IALA"].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:



40
41
42
43
44
# File 'lib/pubid/iala.rb', line 40

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

.identifier_klass_for_type_letter(letter) ⇒ Class<Identifiers::Base>

Look up an identifier class by its IALA type letter (S, R, G, M, C, X, P).

Parameters:

  • letter (String)

Returns:



64
65
66
67
# File 'lib/pubid/iala.rb', line 64

def self.identifier_klass_for_type_letter(letter)
  @by_letter ||= identifier_types.to_h { |klass| [klass.type[:short], klass] }
  @by_letter.fetch(letter.to_s.upcase)
end

.identifier_typesArray<Class>

Auto-discover all identifier types from the Identifiers namespace.

Returns:

  • (Array<Class>)

    identifier classes (Pubid::Identifier subclasses)



31
32
33
34
35
36
# File 'lib/pubid/iala.rb', line 31

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 == Identifiers::Base }
end

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

Lookup: abbreviation -> typed stage

Parameters:

  • abbr (String, Symbol)

Returns:



56
57
58
59
# File 'lib/pubid/iala.rb', line 56

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)

Returns:

  • (Class, nil)


49
50
51
# File 'lib/pubid/iala.rb', line 49

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

.parse(identifier) ⇒ Pubid::Iala::Identifier

Parse an IALA identifier string into an identifier object.

Parameters:

  • identifier (String)

    The IALA identifier string to parse

Returns:



21
22
23
# File 'lib/pubid/iala.rb', line 21

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