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
Stays independent of Pubid::Components::Code because ITU uses subseries (dot-separated, flavor-specific) and parts (dash-separated).
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(number:, subseries: nil, parts: nil) ⇒ Code
constructor
A new instance of Code.
- #render(context: nil) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(number:, subseries: nil, parts: nil) ⇒ Code
Returns a new instance of Code.
20 21 22 23 24 |
# File 'lib/pubid/itu/components/code.rb', line 20 def initialize(number:, subseries: nil, parts: nil) @number = number @subseries = subseries @parts = parts || [] end |
Instance Method Details
#==(other) ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/pubid/itu/components/code.rb', line 37 def ==(other) return false unless other.is_a?(Code) number == other.number && subseries == other.subseries && parts == other.parts end |
#render(context: nil) ⇒ Object
33 34 35 |
# File 'lib/pubid/itu/components/code.rb', line 33 def render(context: nil) to_s end |
#to_s ⇒ Object
26 27 28 29 30 31 |
# File 'lib/pubid/itu/components/code.rb', line 26 def to_s result = number.to_s result += ".#{subseries}" if subseries result += parts.map { |p| "-#{p}" }.join if parts&.any? result end |