Class: Pubid::Itu::Components::Code
- Inherits:
-
Lutaml::Model::Serializable
- Object
- Lutaml::Model::Serializable
- Pubid::Itu::Components::Code
- Defined in:
- lib/pubid/itu/components/code.rb
Overview
ITU Code component Format: NUMBER[-PART] Examples: 1234, 1234.5, 1234-1, 1234.5-2
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(number:, subseries: nil, parts: nil) ⇒ Code
constructor
A new instance of Code.
- #to_s ⇒ Object
Constructor Details
#initialize(number:, subseries: nil, parts: nil) ⇒ Code
Returns a new instance of Code.
16 17 18 19 20 |
# File 'lib/pubid/itu/components/code.rb', line 16 def initialize(number:, subseries: nil, parts: nil) @number = number @subseries = subseries @parts = parts || [] end |
Instance Method Details
#==(other) ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/pubid/itu/components/code.rb', line 29 def ==(other) return false unless other.is_a?(Code) number == other.number && subseries == other.subseries && parts == other.parts end |
#to_s ⇒ Object
22 23 24 25 26 27 |
# File 'lib/pubid/itu/components/code.rb', line 22 def to_s result = number.to_s result += ".#{subseries}" if subseries result += parts.map { |p| "-#{p}" }.join if parts&.any? result end |