Class: Pubid::Iec::Components::Code
- Inherits:
-
Lutaml::Model::Serializable
- Object
- Lutaml::Model::Serializable
- Pubid::Iec::Components::Code
- Defined in:
- lib/pubid/iec/components/code.rb
Class Method Summary collapse
-
.parse(string) ⇒ Object
Parse IEC code formats: - “60034” (just number) - “60034-1” (number with part) - “TR 61000” (with prefix) - “TS 62443” (with prefix).
Instance Method Summary collapse
- #full_code ⇒ Object
-
#initialize(value: nil, number: nil, prefix: nil, part: nil) ⇒ Code
constructor
A new instance of Code.
- #to_s ⇒ Object
Constructor Details
#initialize(value: nil, number: nil, prefix: nil, part: nil) ⇒ Code
Returns a new instance of Code.
12 13 14 15 16 17 |
# File 'lib/pubid/iec/components/code.rb', line 12 def initialize(value: nil, number: nil, prefix: nil, part: nil) # Support both 'value' (for convenience) and 'number' (explicit) @number = value || number @prefix = prefix @part = part end |
Class Method Details
.parse(string) ⇒ Object
Parse IEC code formats:
-
“60034” (just number)
-
“60034-1” (number with part)
-
“TR 61000” (with prefix)
-
“TS 62443” (with prefix)
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/pubid/iec/components/code.rb', line 36 def self.parse(string) parts = string.strip.split(" ", 2) if parts.size == 2 # Has prefix: "TR 61000-1-2" prefix = parts[0] number_part = parts[1] else # No prefix: "60034-1" prefix = nil number_part = parts[0] end # Split number and part number_parts = number_part.split("-", 2) number = number_parts[0] part = number_parts[1] new(prefix: prefix, number: number, part: part) end |
Instance Method Details
#full_code ⇒ Object
27 28 29 |
# File 'lib/pubid/iec/components/code.rb', line 27 def full_code to_s end |
#to_s ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/pubid/iec/components/code.rb', line 19 def to_s result = "" result += "#{prefix} " if prefix result += number result += "-#{part}" if part result end |