Class: Pubid::Nist::Components::Update

Inherits:
Lutaml::Model::Serializable
  • Object
show all
Defined in:
lib/pubid/nist/components/update.rb

Overview

Update component for NIST publications Represents errata updates with number, year, and optional month

Examples:

Update.new(number: 1, year: 2021, month: 2).to_s(:short) # => "/Upd1-202102"
Update.new(number: 3, year: 2015).to_s(:short)           # => "/Upd3-2015"
Update.new(number: 1, year: 2021, month: 2).to_s(:mr)    # => "-upd1-202102"
Update.new(number: 1, prefix: "dash").to_s(:short)       # => "-upd1" (preserves original prefix)

Instance Method Summary collapse

Instance Method Details

#to_s(format = :short) ⇒ String

Render update in specified format

Parameters:

  • format (:short, :mr, :long) (defaults to: :short)

    The output format

Returns:

  • (String)

    The formatted update representation



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/pubid/nist/components/update.rb', line 26

def to_s(format = :short)
  # For MR format, render -upd even without number
  return "-upd" if format == :mr && number.nil? && year.nil?
  # For other formats, return empty string if no number
  return "" if number.nil?

  # Use prefix attribute to determine which prefix to use
  # If prefix is "dash", always use dash prefix regardless of format
  # This preserves original input format (e.g., -upd vs /Upd)
  return build_dash_format if prefix == "dash"

  case format
  when :short
    build_short_format
  when :mr
    build_mr_format
  when :long
    build_long_format
  else
    build_short_format
  end
end