Class: Pubid::Nist::Components::Edition

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

Overview

Edition component for NIST publications per nist-pubid-spec.md Format: <edition-type><edition-id> Types: “-” (historical), “e” (edition), “r” (revision) Edition ID can be: number (“2”) OR year (“2021”) Additional text: Text AFTER “rev” prefix (WITHOUT “rev”)

SEMANTICS:

  • “e” or “edition” = edition (can be number or year or month+year)

  • “r” or “rev” or “revision” or “v” or “version” = revision (can be number or year or month+year)

  • If BOTH edition AND revision in same identifier:

    • Type is “e” (edition takes precedence)

    • ID is the edition value

    • additional_text is the revision part (WITHOUT “rev” prefix)

    • Renders with DOT separator: e2.June1908

Examples:

Edition.new(type: "e", id: "2").to_s                              # => "e2"
Edition.new(type: "e", id: "2", additional_text: "June1908").to_s # => "e2.June1908"
Edition.new(type: "e", id: "2", additional_text: "1908").to_s     # => "e2.1908"
Edition.new(type: "r", id: "1963").to_s                           # => "r1963"
Edition.new(type: "r", id: "5").to_s                              # => "r5"
Edition.new(type: "r", id: "5", original_prefix: " Rev. ").to_s    # => "Rev. 5"

Instance Method Summary collapse

Instance Method Details

#==(other) ⇒ Object Also known as: eql?

Identity ignores original_prefix: it records how the edition was spelled in the source (“Rev. ” vs “r”) for round-trip rendering only. “r1” and “Rev. 1” are the same edition.



55
56
57
58
59
60
# File 'lib/pubid/nist/components/edition.rb', line 55

def ==(other)
  return false unless other.is_a?(self.class)

  type == other.type && id == other.id &&
    additional_text == other.additional_text
end

#hashObject



64
65
66
# File 'lib/pubid/nist/components/edition.rb', line 64

def hash
  [self.class, type, id, additional_text].hash
end

#to_s(format = :short) ⇒ String

Render edition in specified format

Parameters:

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

    The output format

Returns:

  • (String)

    The formatted edition representation



39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/pubid/nist/components/edition.rb', line 39

def to_s(format = :short)
  case format
  when :short, :mr
    build_short_format
  when :long
    build_long_format
  when :abbrev
    build_short_format
  else
    build_short_format
  end
end