Class: Pubid::Components::Code

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

Overview

Document code/number component.

Holds the structured fields that recur across flavors: the main value (always present), plus optional prefix (series/type designator), part, subpart, and free-form parts. Subclasses own their composition rules — flavor-specific separators and orderings live in the subclass #to_s / #render override.

Instance Method Summary collapse

Instance Method Details

#eql?(other) ⇒ Boolean

rubocop:disable Metrics/AbcSize

Returns:

  • (Boolean)


35
36
37
38
39
40
41
42
43
# File 'lib/pubid/components/code.rb', line 35

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

  value == other.value &&
    prefix == other.prefix &&
    part == other.part &&
    subpart == other.subpart &&
    parts == other.parts
end

#hashObject



30
31
32
# File 'lib/pubid/components/code.rb', line 30

def hash
  [value, prefix, part, subpart, parts].hash
end

#render(context: nil) ⇒ Object

Format-aware render seam. Default returns the bare value; subclasses override to compose flavor-specific shapes (e.g. ISO joins parts with “-”, NIST joins subpart with “.”).



26
27
28
# File 'lib/pubid/components/code.rb', line 26

def render(context: nil)
  value.to_s
end

#to_sObject



19
20
21
# File 'lib/pubid/components/code.rb', line 19

def to_s
  value.to_s
end