Class: Pubid::Nist::SupplementIdentifier

Inherits:
Identifiers::Base show all
Defined in:
lib/pubid/nist/supplement_identifier.rb

Overview

Base class for NIST supplement identifiers Supplements wrap a base identifier with additional edition information

Architecture follows ISO pattern:

  • base_identifier: The base document being supplemented

  • edition: Edition information for the supplement

Examples:

  • “NBS CIRC 101e2supp” → CircularSupplement(base: “NBS CIRC 101”, edition: e2)

  • “NBS CIRC 25supp-1924” → CircularSupplement(base: “NBS CIRC 25”, edition: 1924)

Direct Known Subclasses

Identifiers::CircularSupplement

Instance Method Summary collapse

Methods inherited from Identifiers::Base

#edition_greater?, #extract_edition_number, #initialize, #language, #merge, #revision, #series_code, #translation, typed_stages, #weight

Methods inherited from Identifier

#base_identifier, #eql?, #exclude, #hash, #initialize, #mr_number, #mr_number_with_part, #mr_part, #mr_publisher, #mr_type, #mr_year, #new_edition_of?, polymorphic_name, #render, #resolve_urn_generator, #root, #to_mr_string, #to_supplement_s, #to_urn, #urn_supplement_type, #urn_type_code

Constructor Details

This class inherits a constructor from Pubid::Nist::Identifiers::Base

Instance Method Details

#publisherObject

Delegate publisher to base_identifier



19
20
21
# File 'lib/pubid/nist/supplement_identifier.rb', line 19

def publisher
  base_identifier&.publisher
end

#seriesObject

Delegate series to base_identifier



24
25
26
# File 'lib/pubid/nist/supplement_identifier.rb', line 24

def series
  base_identifier&.series
end

#to_s(format = :short) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
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
# File 'lib/pubid/nist/supplement_identifier.rb', line 28

def to_s(format = :short)
  # Handle date range supplements (no base identifier)
  if supplement_date_range_start && supplement_date_range_end
    return "NBS CIRC supp#{supplement_date_range_start}-#{supplement_date_range_end}"
  end

  return super unless base_identifier

  result = base_identifier.to_s(format)

  # NEW: Handle update attribute (e.g., "Upd12-1926" for supplement patterns)
  if update
    # Check if this is an implicit supplement (no explicit "sup/supp" marker, just update)
    # For implicit supplements like "145r11/1925", don't add "sup" before the update
    is_implicit = self.class.attributes.key?(:implicit_supplement) && implicit_supplement == true

    if is_implicit
      # Implicit supplement: "{base}/{update}" (e.g., "145/Upd1-192511")
    else
      # Explicit supplement: "{base}sup/{update}" (e.g., "118sup/Upd12-1926")
      is_circ_supplement = ["LCIRC", "CIRC"].include?(series.to_s)
      result += is_circ_supplement ? "sup" : "supp"
    end
    result += "/#{update}"
    return result
  end

  # Original supplement rendering
  # For LCIRC/CIRC supplements with update, use "sup"
  # For LCIRC/CIRC supplements without update, normalize "sup" to "supp" for consistency
  is_circ_supplement = ["LCIRC", "CIRC"].include?(series.to_s)
  # When update is present, use "sup" (e.g., "118sup/Upd1-192612")
  # When update is not present, use "supp" (e.g., "378Gsupp" - normalized from "sup")
  result += if is_circ_supplement && !update
              "supp"
            elsif is_circ_supplement
              "sup"
            else
              "supp"
            end

  # Add edition information if present (just ID, not type prefix)
  if edition&.id
    # Smart dash logic: month=no dash, year=dash
    result += if edition.id.match?(/^[A-Z]/)
                edition.id
              else
                "-#{edition.id}"
              end
  end

  result
end