Class: Pubid::Nist::Scheme

Inherits:
Scheme
  • Object
show all
Defined in:
lib/pubid/nist/scheme.rb

Overview

Scheme class for NIST identifier registry Single Responsibility: Identifier class registry and series-to-class mapping

Constant Summary collapse

VALID_SERIES =

All valid series codes (comprehensive list)

[
  # Major series with dedicated classes
  "SP", "FIPS", "IR", "HB", "TN",
  # Specialized series with dedicated classes
  "CIRC", "CRPL", "CS", "CSM",
  # Other series (use Base class)
  "GCR", "AMS", "BSS", "BMS", "BH", "MONO", "MP",
  "NCSTAR", "NSRDS", "CSWP", "VTS", "AI", "OWMWP",
  "PC", "RPT", "SIBS", "TIBM", "TTB", "EAB",
  "JPCRD", "JRES", "CIS", "HR", "IRPL", "IP",
  "LC", "PS", "LCIRC",
  # Compound series
  "BRPD-CRPL-D", "CRPL-F-A", "CRPL-F-B", "CS-E",
  "CSRC Building Block", "CSRC Use Case", "CSRC Book",
  "ITL Bulletin", "NIST LC", "NIST PS", "NIST DCI",
  "NIST Other", "NSRDS-NBS"
].freeze

Instance Attribute Summary

Attributes inherited from Scheme

#identifiers, #languages, #publishers, #stages, #supplement_identifiers, #types

Class Method Summary collapse

Methods inherited from Scheme

#all_identifier_classes, #all_typed_stages, #configure, #identifier_class_index, #initialize, #locate_identifier_klass_by_type_code, #locate_typed_stage_by_abbr, #locate_typed_stage_by_harmonized_code, #locate_typed_stage_by_stage_code, #supplement_typed_stages, #typed_stage_index, #typed_stages

Constructor Details

This class inherits a constructor from Pubid::Scheme

Class Method Details

.has_supplement?(parsed_hash) ⇒ Boolean

Check if parsed hash has supplement indicators

Returns:

  • (Boolean)


136
137
138
139
140
141
142
# File 'lib/pubid/nist/scheme.rb', line 136

def has_supplement?(parsed_hash)
  parsed_hash[:supplement] ||
    parsed_hash[:supplement_date_range] ||
    parsed_hash[:supplement_date] ||
    parsed_hash[:supplement_slash_year] ||
    parsed_hash[:supplement_with_rev]
end

.identifiersArray<Class>

All identifier classes

Returns:

  • (Array<Class>)

    list of all identifier classes



146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
# File 'lib/pubid/nist/scheme.rb', line 146

def identifiers
  @identifiers ||= [
    Identifiers::SpecialPublication,
    Identifiers::FederalInformationProcessingStandards,
    Identifiers::InteragencyReport,
    Identifiers::Handbook,
    Identifiers::TechnicalNote,
    Identifiers::Circular,
    Identifiers::CircularSupplement,
    Identifiers::CrplReport,
    Identifiers::Report,
    Identifiers::Monograph,
    Identifiers::MiscellaneousPublication,
    Identifiers::GrantContractorReport,
    Identifiers::Ncstar,
    Identifiers::Owmwp,
    Identifiers::Nsrds,
    Identifiers::LetterCircular,
    Identifiers::CommercialStandard,
    Identifiers::CommercialStandardEmergency,
    Identifiers::CommercialStandardsMonthly,
    Identifiers::Base, # Fallback for unmapped series
  ].freeze
end

.locate_identifier_klass(parsed_hash) ⇒ Class

Locate identifier class by series and pattern

Parameters:

  • parsed_hash (Hash)

    the parsed identifier data

Returns:

  • (Class)

    the identifier class



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/pubid/nist/scheme.rb', line 45

def locate_identifier_klass(parsed_hash)
  series = parsed_hash[:series]&.to_s

  # Handle compound series that include publisher (both space and dot separated)
  if series&.start_with?("NBS ")
    simple_series = series.sub("NBS ", "")

    # Check for CIRC supplement
    if simple_series == "CIRC"
      if has_supplement?(parsed_hash)
        return Identifiers::CircularSupplement
      else
        return Identifiers::Circular
      end
    end

    # Use simple series for lookup (TYPED_STAGES abbr handles compound forms)
    series = simple_series
  elsif series&.start_with?("NBS.")
    # Handle dot-separated patterns (e.g., "NBS.LCIRC" after preprocessing)
    simple_series = series.sub("NBS.", "")

    # Check for LCIRC supplement (dot-separated variant)
    if simple_series == "LCIRC"
      if has_supplement?(parsed_hash)
        return Identifiers::CircularSupplement
      else
        return Identifiers::LetterCircular
      end
    end

    # Check for CIRC supplement (dot-separated variant)
    if simple_series == "CIRC"
      if has_supplement?(parsed_hash)
        return Identifiers::CircularSupplement
      else
        return Identifiers::Circular
      end
    end

    # Use simple series for lookup
    series = simple_series
  elsif series&.start_with?("NIST.")
    # Handle dot-separated NIST patterns
    simple_series = series.sub("NIST.", "")

    # Check for LCIRC supplement (dot-separated variant)
    if simple_series == "LCIRC"
      if has_supplement?(parsed_hash)
        return Identifiers::CircularSupplement
      else
        return Identifiers::LetterCircular
      end
    end

    # Use simple series for lookup
    series = simple_series
  end

  # Check for CS variants (works for both compound "NBS CS" and simple "CS")
  if series == "CS"
    first_num = parsed_hash[:first_number]

    # Check for CSM (monthly) - v#n# pattern inside first_number hash
    if first_num.is_a?(Hash) && first_num[:volume_number] && first_num[:issue_number]
      return Identifiers::CommercialStandardsMonthly
    end

    # Check for CS-E (emergency) - e-prefix with 3+ digits
    # Handle Parslet::Slice by converting to string
    first_num_str = first_num.is_a?(String) ? first_num.to_str : first_num.to_s

    # Match e104 or e104 (when "e104-43" is split into first+second)
    if /^e\d{3,}/.match?(first_num_str)
      return Identifiers::CommercialStandardEmergency
    end
  end

  # Look up using TYPED_STAGES registry (replaces series_to_class_map)
  # This handles simple series, compound series (via abbr array), and all variants
  begin
    typed_stage = locate_typed_stage_by_abbr(series)
    type_code = typed_stage.type_code
    locate_identifier_klass_by_type_code(type_code)
  rescue ArgumentError
    # Fallback to Base for unmapped series (e.g., "AMS", "VTS")
    Identifiers::Base
  end
end

.locate_identifier_klass_by_type_code(type_code) ⇒ Class

Locate identifier class by type code

Parameters:

  • type_code (String, Symbol)

    the type code

Returns:

  • (Class)

    the identifier class

Raises:

  • (ArgumentError)

    if type code not found



33
34
35
36
37
38
39
40
# File 'lib/pubid/nist/scheme.rb', line 33

def locate_identifier_klass_by_type_code(type_code)
  type_str = type_code.to_s
  identifiers
    .reject { |klass| klass == Identifiers::Base } # Skip Base fallback class
    .find do |klass|
      klass.typed_stages.any? { |ts| ts.type_code.to_s == type_str }
    end || raise(ArgumentError, "Unknown type code: #{type_code}")
end

.locate_typed_stage_by_abbr(abbr) ⇒ Components::TypedStage

Locate TypedStage by abbreviation

Parameters:

  • abbr (String, Symbol)

    the type abbreviation

Returns:

Raises:

  • (ArgumentError)

    if abbreviation not found



22
23
24
25
26
27
# File 'lib/pubid/nist/scheme.rb', line 22

def locate_typed_stage_by_abbr(abbr)
  abbr_str = abbr.to_s.upcase
  typed_stages.find do |ts|
    ts.abbr.any? { |a| a.to_s.upcase == abbr_str }
  end || raise(ArgumentError, "Unknown type abbreviation: #{abbr}")
end

.typed_stagesArray<Components::TypedStage>

Aggregate TYPED_STAGES from all identifier classes

Returns:



11
12
13
14
15
16
# File 'lib/pubid/nist/scheme.rb', line 11

def typed_stages
  @typed_stages ||= identifiers
    .reject { |klass| klass == Identifiers::Base } # Skip Base fallback class
    .flat_map(&:typed_stages)
    .freeze
end

.valid_series?(series_code) ⇒ Boolean

Check if series is valid

Parameters:

  • series_code (String)

    the series code

Returns:

  • (Boolean)

    true if series is valid



174
175
176
# File 'lib/pubid/nist/scheme.rb', line 174

def valid_series?(series_code)
  VALID_SERIES.include?(series_code)
end