Module: Pubid::Jcgm

Defined in:
lib/pubid/jcgm.rb,
lib/pubid/jcgm/parser.rb,
lib/pubid/jcgm/builder.rb,
lib/pubid/jcgm/renderer.rb,
lib/pubid/jcgm/components.rb,
lib/pubid/jcgm/identifier.rb,
lib/pubid/jcgm/urn_parser.rb,
lib/pubid/jcgm/identifiers.rb,
lib/pubid/jcgm/urn_generator.rb,
lib/pubid/jcgm/identifiers/guide.rb,
lib/pubid/jcgm/single_identifier.rb,
lib/pubid/jcgm/components/publisher.rb,
lib/pubid/jcgm/identifiers/amendment.rb,
lib/pubid/jcgm/identifiers/gum_guide.rb,
lib/pubid/jcgm/supplement_identifier.rb

Defined Under Namespace

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

Class Method Summary collapse

Class Method Details

.all_typed_stagesArray<Pubid::Components::TypedStage>

Build typed stage index from identifier types

Returns:



42
43
44
45
46
47
48
49
50
# File 'lib/pubid/jcgm.rb', line 42

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



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

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.singleton_methods(false).include?(:type) }
    .select { |c| c.type.is_a?(Hash) }
end

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

Lookup: abbreviation -> typed stage

Parameters:

  • abbr (String, Symbol)

    the abbreviation to find

Returns:



62
63
64
65
# File 'lib/pubid/jcgm.rb', line 62

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



55
56
57
# File 'lib/pubid/jcgm.rb', line 55

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

.parse(identifier) ⇒ Identifier

Parse a JCGM identifier string

Parameters:

  • identifier (String)

    the identifier string to parse

Returns:



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

def self.parse(identifier)
  parser = Parser.new
  builder = Builder.new

  parsed = parser.parse(identifier)
  builder.build(parsed)
end