Class: Pubid::Itu::Components::Code

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

Overview

ITU Code component Format: NUMBER[-PART] Examples: 1234, 1234.5, 1234-1, 1234.5-2

Stays independent of Pubid::Components::Code because ITU uses subseries (dot-separated, flavor-specific) and parts (dash-separated).

Instance Method Summary collapse

Instance Method Details

#==(other) ⇒ Object



31
32
33
34
35
36
37
# File 'lib/pubid/itu/components/code.rb', line 31

def ==(other)
  return false unless other.is_a?(Code)

  number == other.number &&
    subseries == other.subseries &&
    parts == other.parts
end

#render(context: nil) ⇒ Object



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

def render(context: nil)
  to_s
end

#to_sObject



20
21
22
23
24
25
# File 'lib/pubid/itu/components/code.rb', line 20

def to_s
  result = number.to_s
  result += ".#{subseries}" if subseries
  result += parts.map { |p| "-#{p}" }.join if parts&.any?
  result
end