Class: Pubid::Nist::Series::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/pubid/nist/series/base.rb

Overview

Default series behavior. All hooks return the “generic” answer so a series bug can be fixed by overriding the relevant hook in a subclass.

Direct Known Subclasses

LetterPreserving, Ncstar

Class Method Summary collapse

Class Method Details

.cast_letter_number(value, _parsed_hash) ⇒ Object

Cast a ‘:letter_number` parser hash (e.g., from “800-56A”). Return a cast hash, or nil to skip assignment. Default: split letter suffix into a Part component.



18
19
20
21
22
23
# File 'lib/pubid/nist/series/base.rb', line 18

def self.cast_letter_number(value, _parsed_hash)
  full = combine_letter_suffix(value)
  return nil if full.nil? || full.empty?

  { part: Components::Part.new(type: "", value: full.upcase) }
end

.combine_letter_suffix(value) ⇒ Object

Combine ‘:letter_suffix` and `:letter_suffix_extra` (e.g., “U” + “r”).



50
51
52
53
54
# File 'lib/pubid/nist/series/base.rb', line 50

def self.combine_letter_suffix(value)
  suffix = value[:letter_suffix].to_s.strip
  extra = value[:letter_suffix_extra].to_s.strip
  extra.empty? ? suffix : "#{suffix}#{extra}"
end

.finalize_identifier(_identifier, _parsed_hash) ⇒ Object

Hook: post-process the identifier after compound number is assigned. Override to reverse series-specific preprocessing side effects.



47
# File 'lib/pubid/nist/series/base.rb', line 47

def self.finalize_identifier(_identifier, _parsed_hash); end

.handle_letter_num_compound?(_identifier, first_num:, letter_base:, letter_suffix:) ⇒ Boolean

Hook: build compound number when ‘letter_num` is present. Return true if the series handled it; false to fall back to default.

Returns:

  • (Boolean)


39
40
41
42
43
# File 'lib/pubid/nist/series/base.rb', line 39

def self.handle_letter_num_compound?(_identifier,
                                      first_num:, letter_base:,
                                      letter_suffix:)
  false
end

.modern_edition_date?Boolean

Whether the edition-year cast should use modern (numeric) date format instead of preserving historical month names. FIPS uses modern.

Returns:

  • (Boolean)


27
28
29
# File 'lib/pubid/nist/series/base.rb', line 27

def self.modern_edition_date?
  false
end

.part_num_as_component?Boolean

Whether ‘part_num` alongside `second_num` becomes a Part component (true) or is folded into the compound number (false). IR uses Part.

Returns:

  • (Boolean)


33
34
35
# File 'lib/pubid/nist/series/base.rb', line 33

def self.part_num_as_component?
  false
end

.preserve_letter_suffix?(parsed_hash) ⇒ Boolean

Whether an uppercase letter at the end of ‘first_number` stays in the number (true) or is extracted as a separate Part component (false).

Returns:

  • (Boolean)


11
12
13
# File 'lib/pubid/nist/series/base.rb', line 11

def self.preserve_letter_suffix?(parsed_hash)
  parsed_hash[:parsed_format] == :mr
end