Module: Pubid::Ietf

Extended by:
PrefixesSupport
Defined in:
lib/pubid/ietf.rb,
lib/pubid/ietf/parser.rb,
lib/pubid/ietf/builder.rb,
lib/pubid/ietf/renderer.rb,
lib/pubid/ietf/urn_parser.rb,
lib/pubid/ietf/identifiers.rb,
lib/pubid/ietf/urn_generator.rb,
lib/pubid/ietf/identifiers/bcp.rb,
lib/pubid/ietf/identifiers/fyi.rb,
lib/pubid/ietf/identifiers/rfc.rb,
lib/pubid/ietf/identifiers/std.rb,
lib/pubid/ietf/identifiers/base.rb,
lib/pubid/ietf/identifiers/internet_draft.rb

Overview

IETF flavor: one module covering the three IETF document families that share the IETF publisher and the urn:ietf: namespace —

  • RFC (e.g. "RFC 2119") -> Identifiers::Rfc
  • RFC sub-series (BCP/STD/FYI) -> Identifiers::Bcp/Std/Fyi
  • Internet-Drafts (e.g. "draft-...-02") -> Identifiers::InternetDraft

Defined Under Namespace

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

Constant Summary collapse

PREFIXES =

Leading tokens a printed IETF id can begin with. "draft" covers the "draft-" Internet-Draft form. No joint/co-publication prefixes.

["RFC", "BCP", "STD", "FYI", "draft"].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:



48
49
50
51
52
53
54
55
56
# File 'lib/pubid/ietf.rb', line 48

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



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

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:



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

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



61
62
63
# File 'lib/pubid/ietf.rb', line 61

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

.parse(identifier) ⇒ Object

Parse an IETF identifier string

Raises:

  • (ArgumentError)


25
26
27
28
29
30
31
# File 'lib/pubid/ietf.rb', line 25

def self.parse(identifier)
  # Inline length guard (CodeQL rb/polynomial-redos barrier) before the
  # normalization/parse path — must be the first statement.
  raise ArgumentError, Pubid::INPUT_TOO_LONG_MESSAGE if identifier.length > Pubid::MAX_INPUT_LENGTH

  Identifier.parse(identifier)
end