Class: Pubid::Components::Supplement
- Inherits:
-
Lutaml::Model::Serializable
- Object
- Lutaml::Model::Serializable
- Pubid::Components::Supplement
- Defined in:
- lib/pubid/components/supplement.rb
Overview
Supplement component — a structured value-object representing the supplement-specific data (number, date, stage, iteration, type) of a supplement identifier.
Union shape across flavors:
-
type: “amd” (amendment), “cor” (corrigendum), “err” (errata),
"sup" (supplement), or a flavor-specific marker. -
number: bare sequence number (string preserves leading zeros, “1A”
combos, etc.). -
date: publication date of the supplement (Components::Date).
-
range_end_date: end of a date range; presence of this marks the
supplement as a range. (NIST/NBS uses supJan1924-Jun1925.) -
stage: the stage the supplement is in (e.g., WD Amd, CD Amd).
-
iteration: stage iteration (e.g., the “.2” in “WD.2 Amd”).
-
has_revision: “suprev” marker — supplement that itself carries a
revision. (NIST-specific.) -
suffix: escape hatch for patterns not yet modeled.
Format-aware via render(context:). The human form stacks fields in the order they appear in the printed supplement; the URN form joins number and year with “:”.
Constant Summary collapse
- DEFAULT_TYPE =
"sup"- IDENTITY_FIELDS =
%i[ type number date range_end_date stage iteration has_revision suffix ].freeze
- CONTENT_FIELDS =
Fields whose presence indicates the supplement carries data. ‘type` is excluded — it always has a value (the default “sup”) but doesn’t mean the supplement carries content.
%i[ number date range_end_date stage iteration has_revision suffix ].freeze
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #hash ⇒ Object
-
#present? ⇒ Boolean
True when the supplement carries any data.
-
#range? ⇒ Boolean
True when this supplement spans a date range (start + end set).
- #render(context: nil) ⇒ Object
- #to_s(**opts) ⇒ Object
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
72 73 74 75 76 |
# File 'lib/pubid/components/supplement.rb', line 72 def ==(other) return false unless other.is_a?(self.class) identity_fields.all? { |f| public_send(f) == other.public_send(f) } end |
#hash ⇒ Object
80 81 82 |
# File 'lib/pubid/components/supplement.rb', line 80 def hash @hash ||= [self.class, *identity_fields.map { |f| public_send(f) }].hash end |
#present? ⇒ Boolean
True when the supplement carries any data. Distinguishes a present- but-empty supplement (bare marker, “sup”) from no supplement at all.
53 54 55 |
# File 'lib/pubid/components/supplement.rb', line 53 def present? CONTENT_FIELDS.any? { |f| present_value?(public_send(f)) } end |
#range? ⇒ Boolean
True when this supplement spans a date range (start + end set).
58 59 60 |
# File 'lib/pubid/components/supplement.rb', line 58 def range? date&.present? && range_end_date&.present? end |
#render(context: nil) ⇒ Object
62 63 64 65 66 |
# File 'lib/pubid/components/supplement.rb', line 62 def render(context: nil) return render_urn if context&.format == :urn render_human end |
#to_s(**opts) ⇒ Object
68 69 70 |
# File 'lib/pubid/components/supplement.rb', line 68 def to_s(**opts) render(context: opts[:context]) end |