Class: Pubid::Jis::Components::Code
- Inherits:
-
Lutaml::Model::Serializable
- Object
- Lutaml::Model::Serializable
- Pubid::Jis::Components::Code
- Defined in:
- lib/pubid/jis/components/code.rb
Overview
Represents a JIS code with series letter, number, and optional parts Examples:
A 0001 => series: "A", number: 1, parts: []
B 0060-1 => series: "B", number: 60, parts: [1]
C 61000-3-2 => series: "C", number: 61000, parts: [3, 2]
C 5401-2-001 => series: "C", number: 5401, parts: [2, 1] (with formatting)
Instance Attribute Summary collapse
-
#number_string ⇒ Object
Store original string representations for formatting.
-
#part_strings ⇒ Object
Store original string representations for formatting.
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(series:, number:, parts: nil, number_string: nil, part_strings: nil) ⇒ Code
constructor
A new instance of Code.
-
#to_s ⇒ Object
Render as “SERIES NUMBER[-PART[-SUBPART]]”.
Constructor Details
#initialize(series:, number:, parts: nil, number_string: nil, part_strings: nil) ⇒ Code
Returns a new instance of Code.
22 23 24 25 26 27 28 29 |
# File 'lib/pubid/jis/components/code.rb', line 22 def initialize(series:, number:, parts: nil, number_string: nil, part_strings: nil) @series = series @number = number @parts = parts || [] @number_string = number_string || format_number(number) @part_strings = part_strings || @parts.map(&:to_s) end |
Instance Attribute Details
#number_string ⇒ Object
Store original string representations for formatting
20 21 22 |
# File 'lib/pubid/jis/components/code.rb', line 20 def number_string @number_string end |
#part_strings ⇒ Object
Store original string representations for formatting
20 21 22 |
# File 'lib/pubid/jis/components/code.rb', line 20 def part_strings @part_strings end |
Instance Method Details
#==(other) ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/pubid/jis/components/code.rb', line 38 def ==(other) return false unless other.is_a?(Code) series == other.series && number == other.number && parts == other.parts end |
#to_s ⇒ Object
Render as “SERIES NUMBER[-PART[-SUBPART]]”
32 33 34 35 36 |
# File 'lib/pubid/jis/components/code.rb', line 32 def to_s result = "#{series} #{number_string}" result += part_strings.map { |p| "-#{p}" }.join if part_strings&.any? result end |