Class: Pubid::Nist::Identifier
- Inherits:
-
Identifier
- Object
- Lutaml::Model::Serializable
- Identifier
- Pubid::Nist::Identifier
- Defined in:
- lib/pubid/nist/identifiers/base.rb
Overview
NIST/NBS flavor base class. Canonical name Pubid::Nist::Identifier; every
concrete NIST identifier (Identifiers::*) descends from it. Being a real Pubid::Identifier subclass gives
native is_a? identity and the shared polymorphic from_hash.
Direct Known Subclasses
Pubid::Nist::Identifiers::Circular, Pubid::Nist::Identifiers::CommercialStandard, Pubid::Nist::Identifiers::CommercialStandardEmergency, Pubid::Nist::Identifiers::CommercialStandardsMonthly, Pubid::Nist::Identifiers::CrplReport, Pubid::Nist::Identifiers::DatedDocument, Pubid::Nist::Identifiers::FederalInformationProcessingStandards, Pubid::Nist::Identifiers::GrantContractorReport, Pubid::Nist::Identifiers::Handbook, Pubid::Nist::Identifiers::InteragencyReport, Pubid::Nist::Identifiers::LetterCircular, Pubid::Nist::Identifiers::MiscellaneousPublication, Pubid::Nist::Identifiers::Monograph, Pubid::Nist::Identifiers::Ncstar, Pubid::Nist::Identifiers::Nsrds, Pubid::Nist::Identifiers::Owmwp, Pubid::Nist::Identifiers::Report, Pubid::Nist::Identifiers::SpecialPublication, Pubid::Nist::Identifiers::TechnicalNote, SupplementIdentifier
Constant Summary collapse
- COMPACT_FLAT_CODES =
Compact, index-friendly serialization (mirrors the key_value flavors ISO/ITU/ETSI, without a 38-field key_value block). Two transforms, applied symmetrically by to_hash/from_hash so the round-trip stays idempotent:
- flatten the single-value Code components (series, number) to bare scalars — `value` is the only stored field. NIST's `Components::Code#part` is a *computed* reader (`value.split("-").last`), and prefix/subpart/parts are never assigned on series/number, so the scalar `value` is lossless: expand recomputes exactly what the object would compute anyway; - flatten the plain single-value components (volume) to bare scalars too — `Components::Volume` holds only `value`, so it expands to a bare { "value" => … } with no part; - drop the redundant build artifacts, decomposed pieces of the canonical number that identity/rendering never read. %w[series number subseries].freeze
- COMPACT_FLAT_VALUES =
%w[volume].freeze
- COMPACT_DROP_ATTRS =
%w[first_number second_number].freeze
- EQUALITY_IGNORED_ATTRS =
Attributes that are build artifacts or rendering aliases, not part of an identifier's logical identity. They diverge between equally- valid spellings of the same id (e.g. long "Rev. 1" vs short "r1"):
- first_number/second_number: decomposed parts of the canonical :number, retained from the parse for building - parsed_format: records the input format for round-trip rendering - subseries: derived from series+number (which SP subseries the document belongs to); populated by the Builder for known SP subseries codes. Ignored in equality so a manually-built id without subseries set still equals a parsed one. %i[ first_number second_number parsed_format subseries ].freeze
Class Method Summary collapse
-
.expand_code(value) ⇒ Object
A flattened Code scalar -> { "value" => …, "part" =>
}. -
.expand_compact_hash(data) ⇒ Object
Expand a compact hash in place-safe fashion: a scalar series/number becomes { "value" => …, "part" =>
}. -
.from_hash(data, options = {}) ⇒ Object
Deserialize a (possibly compact) hash: expand the flattened scalars back into Code sub-hashes, then let the shared polymorphic from_hash do the real work.
-
.parse(identifier) ⇒ Object
Delegate to the flavor module so callers can use
Pubid::Nist::Identifier.parseconsistently with other flavors. -
.typed_stages ⇒ Object
Default: no typed stages.
Instance Method Summary collapse
-
#==(other) ⇒ Object
(also: #eql?)
Logical identity comparison: equal when every attribute except the build artifacts/aliases above matches.
-
#append_mr_components(skip_part: false) ⇒ Object
Render the optional component tail for machine-readable (MR) form.
-
#append_short_components(skip_part: false) ⇒ Object
Render the optional component "tail" that follows publisher/series/number in short (human) form.
-
#default_publisher ⇒ Object
Default publisher for series without explicit publisher Subclasses can override.
-
#edition_greater?(edition1, edition2) ⇒ Boolean
Helper to compare edition values numerically.
-
#extract_edition_number(edition) ⇒ Integer?
Extract numeric value from edition (r3 -> 3, r5 -> 5, e2 -> 2).
- #hash ⇒ Object
-
#initialize(**attributes) ⇒ Identifier
constructor
A new instance of Identifier.
-
#language ⇒ Object
Backward compatibility: language method returns translation_component This allows tests to use parsed.language instead of parsed.translation_component.
-
#matches?(candidate) ⇒ Boolean
Wildcard / partial-identifier match.
-
#merge(document) ⇒ Base
Merge another document into this one Used for combining document data, preferring more specific values.
- #publisher_abbreviated_name ⇒ Object
- #publisher_full_name ⇒ Object
-
#render(format: :human, **opts) ⇒ Object
Override parent render to pass NIST-specific format option through to the renderer.
-
#revision ⇒ String?
Derived, read-only revision string ("r5", "e1979", "-3") for backward compatibility.
- #series_abbreviated_name ⇒ Object
-
#series_code ⇒ Object
Default series_code — subclasses override to provide a normalized series name.
- #series_full_name ⇒ Object
-
#supplement_short ⇒ Object
Short-form supplement fragment ("sup", "sup1924", "supJan1924", "suprev", " supJun1925-Jun1926"), rendered from the structured component.
- #to_abbreviated_style ⇒ Object
- #to_full_style ⇒ Object
-
#to_hash(*args) ⇒ Object
Serialize, then apply the compact transforms (recursing into a nested
base, which lutaml serialized via its own transform — bypassing this override — so it is not compacted otherwise). -
#to_mr_string ⇒ Object
NIST has its own defined MR format (to_mr_style) used by relaton-nist and downstream tooling.
- #to_mr_style ⇒ Object
-
#to_s(format = nil) ⇒ Object
Generate identifier string in specified format.
- #to_short_style ⇒ Object
-
#to_slug ⇒ Object
NIST's MR shape is fixed by the pubid standard and stays uppercase (e.g.
NIST.SP.800-53). -
#translation ⇒ Object
Backward compatibility: translation method returns translation_component This allows tests to use parsed.translation.language instead of parsed.translation_component.language.
-
#weight ⇒ Integer
Returns weight based on amount of defined attributes Used for ranking identifiers by specificity for conflict resolution.
Methods inherited from Identifier
apply_mappings, #base, #base_document, concrete_class_for, #dated_version_of?, #draft_of?, #drop_supplements, #edition_of?, #exclude, #has_supplement?, #includes?, #mr_all_parts, #mr_edition, #mr_languages, #mr_number, #mr_number_with_part, #mr_part, #mr_publisher, #mr_subpart, #mr_supplement_suffix, #mr_type, #mr_year, #new_edition_of?, polymorphic_name, polymorphic_type_map, #related_to?, #resolve_urn_generator, #root, #sibling_of?, #supplement_of?, #to_supplement_s, #to_urn, #urn_supplement_type, #urn_type_code, #year
Constructor Details
#initialize(**attributes) ⇒ Identifier
Returns a new instance of Identifier.
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 |
# File 'lib/pubid/nist/identifiers/base.rb', line 172 def initialize(**attributes) super() attrs = self.class.attributes attributes.each do |key, value| next if value.nil? setter = :"#{key}=" public_send(setter, value) if attrs.key?(key) end # NOTE: Compound number building is handled by the Builder class # Do NOT build compound numbers here - let the builder apply special patterns first # See lib/pubid/nist/builder.rb lines 368-472 for compound number logic end |
Class Method Details
.expand_code(value) ⇒ Object
A flattened Code scalar -> { "value" => …, "part" =>
58 59 60 61 62 |
# File 'lib/pubid/nist/identifiers/base.rb', line 58 def self.(value) code = { "value" => value } code["part"] = value.split("-").last if value.include?("-") code end |
.expand_compact_hash(data) ⇒ Object
Expand a compact hash in place-safe fashion: a scalar series/number
becomes { "value" => …, "part" =>
44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/pubid/nist/identifiers/base.rb', line 44 def self.(data) return data unless data.is_a?(::Hash) out = data.dup COMPACT_FLAT_CODES.each do |key| out[key] = (out[key]) if out[key].is_a?(::String) end COMPACT_FLAT_VALUES.each do |key| out[key] = { "value" => out[key] } if out[key].is_a?(::String) end out end |
.from_hash(data, options = {}) ⇒ Object
Deserialize a (possibly compact) hash: expand the flattened scalars
back into Code sub-hashes, then let the shared polymorphic from_hash
do the real work. Nested base documents are expanded recursively by
their own from_hash via apply_mappings, so only this level is touched.
38 39 40 |
# File 'lib/pubid/nist/identifiers/base.rb', line 38 def self.from_hash(data, = {}) super((data), ) end |
.parse(identifier) ⇒ Object
Delegate to the flavor module so callers can use
Pubid::Nist::Identifier.parse consistently with other flavors.
11 12 13 |
# File 'lib/pubid/nist/identifiers/base.rb', line 11 def self.parse(identifier) Pubid::Nist.parse(identifier) end |
.typed_stages ⇒ Object
Default: no typed stages. Subclasses override as needed.
87 88 89 |
# File 'lib/pubid/nist/identifiers/base.rb', line 87 def self.typed_stages [] end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
Logical identity comparison: equal when every attribute except the build artifacts/aliases above matches. (Edition#== already ignores its rendering-only original_prefix.)
205 206 207 208 209 210 211 |
# File 'lib/pubid/nist/identifiers/base.rb', line 205 def ==(other) return false unless other.instance_of?(self.class) self.class.attributes.each_key.all? do |name| EQUALITY_IGNORED_ATTRS.include?(name) || public_send(name) == other.public_send(name) end end |
#append_mr_components(skip_part: false) ⇒ Object
Render the optional component tail for machine-readable (MR) form. Mirrors #append_short_components so the MR output is just as lossless; subclasses that override #to_mr_style reuse this instead of hand-listing components. skip_part: behaves as in the short helper.
644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 |
# File 'lib/pubid/nist/identifiers/base.rb', line 644 def append_mr_components(skip_part: false) result = "" effective_part = skip_part ? nil : part # Volume / Part components (pt1, v6n1, etc.) if volume.is_a?(Components::Volume) && effective_part.is_a?(Components::Part) result += "#{volume}#{effective_part}" elsif effective_part.is_a?(Components::Part) result += effective_part.to_s elsif volume && !issue_number && !effective_part result += (volume.is_a?(Components::Volume) ? volume.to_s : "v#{volume}") elsif volume && issue_number vol_str = volume.is_a?(Components::Volume) ? volume.to_s : "v#{volume}" result += "#{vol_str}n#{issue_number.number}" end # Use edition component - NO space before edition in MR format (per NIST spec) result += edition.to_s if edition # Use version_component result += version_component.to_s(:mr) if version_component # Supplement (e.g. ".9981sup7") - keep distinct documents distinct result += supplement_short # Use update_component result += update_component.to_s(:mr) if update_component # Use stage result += ".#{stage.to_s(:mr)}" if stage # Add addendum - render as ".Add." suffix in MR format if addendum || addendum_number result += ".Add." end # Use translation_component result += translation_component.to_s(:mr) if translation_component result end |
#append_short_components(skip_part: false) ⇒ Object
Render the optional component "tail" that follows publisher/series/number in short (human) form. Extracted from #to_short_style so subclasses that build a series-specific prefix can reuse it instead of hand-listing components (and forgetting some).
skip_part: true lets a series that renders its part differently (e.g. FIPS uses dash "-1", not "pt1") emit the part itself and skip the generic part rendering here, while still getting volume/edition/ supplement/etc.
523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 |
# File 'lib/pubid/nist/identifiers/base.rb', line 523 def append_short_components(skip_part: false) result = "" effective_part = skip_part ? nil : part # Volume and Part components (v6n1 notation for CSM, pt1 for SP) if volume.is_a?(Components::Volume) && effective_part.is_a?(Components::Part) # CSM series: v#n# notation result += " #{volume}#{effective_part}" elsif effective_part.is_a?(Components::Part) # SP and other series: use Part.type to determine format result += effective_part.to_s # Legacy: Render standalone volume (not part of v#n#) elsif volume && !issue_number && !effective_part vol_str = volume.is_a?(Components::Volume) ? volume.to_s : "v#{volume}" result += vol_str elsif volume && issue_number # Render volume and issue number in short form: "v6n12" vol_str = volume.is_a?(Components::Volume) ? volume.to_s : "v#{volume}" result += "#{vol_str}n#{issue_number.number}" end # Use edition component properly (e2, e2021, r5, -3) # NO space before edition when number present (per NIST spec) # Only add space for bare edition (no number case) or if original_prefix has specific format if edition if edition.original_prefix && !edition.original_prefix.empty? # original_prefix includes the full prefix (e.g., " Rev. " for verbose format) result += edition.to_s elsif number # Number present, NO space: "800-53r5" result += edition.to_s else # Bare edition, add space: " r5" result += " #{edition}" end end # Use version_component if available, else use version string. # Attach directly (no leading space) to match edition rendering # (e.g. "800-53r5"), so version reads "800-45ver2" not # "800-45 ver2". if version_component result += version_component.to_s(:short) elsif version result += "ver#{version}" end # Add supplement. NIST/NBS canonical short form is single-p "sup" # with the suffix attached directly, no dash (relaton-data-nist # uses "sup2", "sup1940", "supA"); date-range keeps its inner dash. # Rendered from the structured component; a present-but-empty # component is the bare "sup" marker. result += supplement_short # Add other attributes result += errata.to_s if errata result += "index" if index result += "insert" if insert result += "sec#{section}" if section result += "app" if appendix # Add addendum - render as " Add." suffix if addendum || addendum_number result += " Add." end # Use update_component if available, else use update string if update_component result += update_component.to_s(:short) elsif update result += "-upd#{update}" end # Add draft - render as {N}pd if draft_number present if draft_number result += " #{draft_number}pd" elsif draft&.to_s&.include?("draft") && !draft.to_s.include?("Draft)") result += "-draft" end # Add stage component (at end, before translation) if stage result += " #{stage.to_s(:short)}" end # Use translation_component if available, else use translation string # Note: translation_component.to_s already includes the space prefix if translation_component result += translation_component.to_s(:short) elsif translation result += " #{translation}" end result end |
#default_publisher ⇒ Object
Default publisher for series without explicit publisher Subclasses can override
728 729 730 |
# File 'lib/pubid/nist/identifiers/base.rb', line 728 def default_publisher "NIST" end |
#edition_greater?(edition1, edition2) ⇒ Boolean
Helper to compare edition values numerically
383 384 385 386 387 |
# File 'lib/pubid/nist/identifiers/base.rb', line 383 def edition_greater?(edition1, edition2) num1 = extract_edition_number(edition1) num2 = extract_edition_number(edition2) num1 && num2 && num1 > num2 end |
#extract_edition_number(edition) ⇒ Integer?
Extract numeric value from edition (r3 -> 3, r5 -> 5, e2 -> 2)
391 392 393 394 395 396 397 |
# File 'lib/pubid/nist/identifiers/base.rb', line 391 def extract_edition_number(edition) # Handle both String and Edition component edition_str = edition.to_s # Match patterns like r3, r5, e2, etc. match = edition_str.match(/^[er]?(\d+)$/) match ? match[1].to_i : nil end |
#hash ⇒ Object
215 216 217 218 219 220 |
# File 'lib/pubid/nist/identifiers/base.rb', line 215 def hash vals = self.class.attributes.each_key.reject do |name| EQUALITY_IGNORED_ATTRS.include?(name) end.map { |name| public_send(name) } [self.class, *vals].hash end |
#language ⇒ Object
Backward compatibility: language method returns translation_component This allows tests to use parsed.language instead of parsed.translation_component
282 283 284 |
# File 'lib/pubid/nist/identifiers/base.rb', line 282 def language translation_component end |
#matches?(candidate) ⇒ Boolean
Wildcard / partial-identifier match. Treats self as a QUERY pattern
and candidate as a concrete document: every ID part SET on the query
must equal the candidate's, while parts left unset (nil/empty) are
wildcards that match any value. So a query carrying no edition and no
supplement matches that document across ALL editions, years, and
supplements — the basis for "select docs by ID parts".
Asymmetric (unlike ==): "NBS CIRC 25".matches?("NBS CIRC 25sup1924") is true, but not the reverse. The candidate must be the same class or a subclass so series-level identity still holds.
232 233 234 235 236 237 238 239 240 241 242 243 244 245 |
# File 'lib/pubid/nist/identifiers/base.rb', line 232 def matches?(candidate) return false unless candidate.is_a?(self.class) self.class.attributes.each_key.all? do |name| next true if EQUALITY_IGNORED_ATTRS.include?(name) query_val = public_send(name) next true if query_val.nil? next true if query_val.is_a?(String) && query_val.empty? next true if query_val.is_a?(Array) && query_val.empty? query_val == candidate.public_send(name) end end |
#merge(document) ⇒ Base
Merge another document into this one Used for combining document data, preferring more specific values
347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 |
# File 'lib/pubid/nist/identifiers/base.rb', line 347 def merge(document) return self unless document.is_a?(Pubid::Nist::Identifier) attrs = self.class.attributes attrs.each_key do |var_name| next if var_name == :rendering_style next if var_name == :parsed_format current_val = public_send(var_name) new_val = document.public_send(var_name) next unless new_val should_merge = case var_name when :publisher, :series, :number true when :edition current_val.nil? || edition_greater?(new_val, current_val) when :volume, :part, :version current_val.nil? || (new_val.to_s.length > current_val.to_s.length) when :supplement, :errata, :index, :insert, :section, :appendix, :translation true when :year, :month, :update, :draft true else false end public_send(:"#{var_name}=", new_val) if should_merge end self end |
#publisher_abbreviated_name ⇒ Object
715 716 717 718 719 720 721 722 723 724 |
# File 'lib/pubid/nist/identifiers/base.rb', line 715 def publisher_abbreviated_name case publisher.to_s when "NBS" "Natl. Bur. Stand." when "NIST" "Natl. Inst. Stand. Technol." else publisher.to_s end end |
#publisher_full_name ⇒ Object
704 705 706 707 708 709 710 711 712 713 |
# File 'lib/pubid/nist/identifiers/base.rb', line 704 def publisher_full_name case publisher.to_s when "NBS" "National Bureau of Standards" when "NIST" "National Institute of Standards and Technology" else publisher.to_s end end |
#render(format: :human, **opts) ⇒ Object
Override parent render to pass NIST-specific format option through to the renderer. Pubid::Identifier#render only forwards :with_edition; NIST needs :nist_format for multi-format support.
289 290 291 292 293 294 295 296 297 298 299 300 301 |
# File 'lib/pubid/nist/identifiers/base.rb', line 289 def render(format: :human, **opts) registry = self.class.format_registry unless registry raise ArgumentError, "No format registry configured on #{self.class}" end renderer = registry.renderer_for(format) unless renderer raise ArgumentError, "No renderer registered for format: #{format}" end renderer.new(self).render(**opts) end |
#revision ⇒ String?
Derived, read-only revision string ("r5", "e1979", "-3") for backward
compatibility. edition is the single stored representation; this is
never persisted, compared, or merged — just a convenience view of it.
270 271 272 |
# File 'lib/pubid/nist/identifiers/base.rb', line 270 def revision "#{edition.type}#{edition.id}" if edition&.type && edition.id end |
#series_abbreviated_name ⇒ Object
695 696 697 698 699 700 701 702 |
# File 'lib/pubid/nist/identifiers/base.rb', line 695 def series_abbreviated_name { "SP" => "Spec. Publ.", "FIPS" => "Fed. Inf. Proc. Stand.", "IR" => "Interag. Rep.", "TN" => "Tech. Note", }[series&.to_s || series_code] || (series&.to_s || series_code) end |
#series_code ⇒ Object
Default series_code — subclasses override to provide a normalized series name.
168 169 170 |
# File 'lib/pubid/nist/identifiers/base.rb', line 168 def series_code nil end |
#series_full_name ⇒ Object
686 687 688 689 690 691 692 693 |
# File 'lib/pubid/nist/identifiers/base.rb', line 686 def series_full_name { "SP" => "Special Publication", "FIPS" => "Federal Information Processing Standards", "IR" => "Interagency Report", "TN" => "Technical Note", }[series] || series end |
#supplement_short ⇒ Object
Short-form supplement fragment ("sup", "sup1924", "supJan1924", "suprev", " supJun1925-Jun1926"), rendered from the structured component. A present-but-empty component is the bare "sup" marker; a number-less date range gets the leading space the number would have supplied. Shared by base and the per-series to_short_style overrides.
258 259 260 261 262 263 264 |
# File 'lib/pubid/nist/identifiers/base.rb', line 258 def supplement_short return "" unless supplement prefix = supplement.range? && !number ? " " : "" rendered = supplement.to_s(:short) prefix + (rendered.empty? ? "sup" : rendered) end |
#to_abbreviated_style ⇒ Object
435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 |
# File 'lib/pubid/nist/identifiers/base.rb', line 435 def to_abbreviated_style # "Natl. Inst. Stand. Technol. Spec. Publ. 800-57 Part 1, Revision 4" result = publisher_abbreviated_name result += " #{series_abbreviated_name}" if series result += " #{number}" if number result += " Part #{parts.first}" if parts&.any? # NEW: Use edition component properly result += " #{edition.to_s(:abbrev)}" if edition result += ", Revision #{revision}" if revision # V2: Use version_component result += " #{version_component.to_s(:abbrev)}" if version_component # V2: Use update_component result += " #{update_component.to_s(:abbrev)}" if update_component # V2: Use stage result += " #{stage.to_s(:abbrev)}" if stage # V2: Use translation_component result += ", #{translation_component.to_s(:abbrev)}" if translation_component result end |
#to_full_style ⇒ Object
401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 |
# File 'lib/pubid/nist/identifiers/base.rb', line 401 def to_full_style # "National Institute of Standards and Technology Special Publication 800-27, Revision A" result = publisher_full_name result += " #{series_full_name}" if series result += " #{number.value}" if number result += parts.map { |p| "-#{p}" }.join if parts&.any? # Render volume and issue number in long form: "Vol. 6, No. 12" if volume && issue_number result += " Vol. #{volume}, #{issue_number.to_s(:long)}" elsif volume result += " Vol. #{volume}" end # NEW: Use edition component properly result += " #{edition.to_s(:long)}" if edition result += ", Revision #{revision.sub(/^r/, '')}" if revision # V2: Use version_component result += " #{version_component.to_s(:long)}" if version_component # V2: Use update_component result += " #{update_component.to_s(:long)}" if update_component # V2: Use stage result += " #{stage.to_s(:long)}" if stage # V2: Use translation_component (already includes space) result += translation_component.to_s(:long) if translation_component result end |
#to_hash(*args) ⇒ Object
Serialize, then apply the compact transforms (recursing into a nested
base, which lutaml serialized via its own transform — bypassing this
override — so it is not compacted otherwise).
67 68 69 70 71 |
# File 'lib/pubid/nist/identifiers/base.rb', line 67 def to_hash(*args) hash = super compact_hash!(hash) if hash.is_a?(::Hash) hash end |
#to_mr_string ⇒ Object
NIST has its own defined MR format (to_mr_style) used by relaton-nist and downstream tooling. The generic Renderers::MrString does not know about NIST series, revisions, supplements, etc., so delegate to the established style for losslessness (issue #142).
320 321 322 |
# File 'lib/pubid/nist/identifiers/base.rb', line 320 def to_mr_string to_mr_style end |
#to_mr_style ⇒ Object
619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 |
# File 'lib/pubid/nist/identifiers/base.rb', line 619 def to_mr_style # "NIST.SP.800-116r1.ipd" (machine-readable with dots) result = (publisher || "NIST").to_s # Determine effective series - PREFER series_code if subclass defines it # This allows normalization (e.g., LCIRC → LC in LetterCircular) effective_series = if series_code series_code elsif series series.to_s end result += ".#{effective_series}" if effective_series result += ".#{number}" if number result += parts.map { |p| "-#{p}" }.join if parts&.any? result += append_mr_components result end |
#to_s(format = nil) ⇒ Object
Generate identifier string in specified format
305 306 307 308 309 310 311 312 313 314 |
# File 'lib/pubid/nist/identifiers/base.rb', line 305 def to_s(format = nil) # Handle both keyword argument (hash) and positional argument (symbol/string) format = format[:format] if format.is_a?(Hash) # Default to parsed_format if available (preserves input format on round-trip) # Falls back to :short format for output (normalization) # Explicit format parameter always overrides parsed_format render(format: :human, nist_format: format || parsed_format&.to_sym || :short) end |
#to_short_style ⇒ Object
462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 |
# File 'lib/pubid/nist/identifiers/base.rb', line 462 def to_short_style # "SP 800-187" or "NIST SP 800-187" - handle compound series properly result = "" # Determine effective publisher # Only show publisher if it was explicitly parsed (either directly or from series prefix) effective_publisher = if publisher && publisher_was_parsed # Publisher was in input (either as separate field or extracted from "NBS CS" series) publisher.to_s else # No publisher in input, don't show default nil end # Determine effective series - PREFER series_code if subclass defines it # This allows normalization (e.g., LCIRC → LC in LetterCircular) effective_series = if series_code series_code elsif series series.to_s end # Special handling for compound series that include publisher prefix # If series starts with "NBS " (like "NBS CIRC"), use it as-is if effective_series&.start_with?("NBS ") result += effective_series elsif effective_publisher && effective_series result += "#{effective_publisher} #{effective_series}" elsif effective_series && publisher_was_parsed # Only add "NIST" prefix if publisher was explicitly in the input result += "NIST #{effective_series}" elsif effective_series # No publisher in input, just show series without prefix result += effective_series end result += " #{number}" if number result += parts.map { |p| "-#{p}" }.join if parts&.any? # "NIST Research Library (YYYY)" — oddball identifier with no number; # the year appears in parens rather than as a date component. result += " (#{year})" if year && !number # Append every optional component the parser may have attached # (volume, part, edition, version, supplement, update, stage, ...). # Shared with the lossy subclasses so they cannot silently drop a # distinguishing component and collide with another document. result += append_short_components result end |
#to_slug ⇒ Object
NIST's MR shape is fixed by the pubid standard and stays uppercase
(e.g. NIST.SP.800-53). The slug, however, must be lowercase to
match the cross-flavor convention; project the MR through downcase.
327 328 329 |
# File 'lib/pubid/nist/identifiers/base.rb', line 327 def to_slug to_mr_string.downcase end |
#translation ⇒ Object
Backward compatibility: translation method returns translation_component This allows tests to use parsed.translation.language instead of parsed.translation_component.language
276 277 278 |
# File 'lib/pubid/nist/identifiers/base.rb', line 276 def translation translation_component end |
#weight ⇒ Integer
Returns weight based on amount of defined attributes Used for ranking identifiers by specificity for conflict resolution
334 335 336 337 338 339 340 341 |
# File 'lib/pubid/nist/identifiers/base.rb', line 334 def weight self.class.attributes.keys.inject(0) do |sum, key| next sum if EQUALITY_IGNORED_ATTRS.include?(key) val = public_send(key) val && !val.to_s.empty? ? sum + 1 : sum end end |