Module: Pubid::Iho
- Defined in:
- lib/pubid/iho.rb,
lib/pubid/iho/parser.rb,
lib/pubid/iho/builder.rb,
lib/pubid/iho/renderer.rb,
lib/pubid/iho/identifier.rb,
lib/pubid/iho/urn_parser.rb,
lib/pubid/iho/identifiers.rb,
lib/pubid/iho/urn_generator.rb,
lib/pubid/iho/identifiers/base.rb,
lib/pubid/iho/identifiers/standard.rb,
lib/pubid/iho/identifiers/publication.rb,
lib/pubid/iho/identifiers/bibliographic.rb,
lib/pubid/iho/identifiers/miscellaneous.rb,
lib/pubid/iho/identifiers/circular_letter.rb
Defined Under Namespace
Modules: Identifier, Identifiers Classes: Builder, Parser, Renderer, UrnGenerator, UrnParser
Class Method Summary collapse
-
.all_typed_stages ⇒ Array<Pubid::Components::TypedStage>
Build typed stage index from identifier types.
-
.identifier_klass_for_type_letter(letter) ⇒ Class<Identifiers::Base>
Look up an identifier class by its IHO series letter (S/P/M/B/C).
-
.identifier_types ⇒ Array<Class>
Auto-discover all identifier types from the Identifiers namespace.
-
.locate_stage(abbr) ⇒ Pubid::Components::TypedStage?
Lookup: abbreviation -> typed stage.
-
.locate_type(code) ⇒ Class?
Lookup: type code -> identifier class.
-
.parse(identifier) ⇒ Pubid::Iho::Identifiers::Base
Parse an IHO identifier string into an identifier object.
Class Method Details
.all_typed_stages ⇒ Array<Pubid::Components::TypedStage>
Build typed stage index from identifier types
35 36 37 38 39 40 41 42 43 |
# File 'lib/pubid/iho.rb', line 35 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_klass_for_type_letter(letter) ⇒ Class<Identifiers::Base>
Look up an identifier class by its IHO series letter (S/P/M/B/C).
63 64 65 66 |
# File 'lib/pubid/iho.rb', line 63 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) end |
.identifier_types ⇒ Array<Class>
Auto-discover all identifier types from the Identifiers namespace.
26 27 28 29 30 31 |
# File 'lib/pubid/iho.rb', line 26 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
55 56 57 58 |
# File 'lib/pubid/iho.rb', line 55 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
48 49 50 |
# File 'lib/pubid/iho.rb', line 48 def self.locate_type(code) identifier_types.find { |t| t.type[:key].to_s == code.to_s } end |
.parse(identifier) ⇒ Pubid::Iho::Identifiers::Base
Parse an IHO identifier string into an identifier object
16 17 18 |
# File 'lib/pubid/iho.rb', line 16 def self.parse(identifier) Identifier.parse(identifier) end |