Class: Pubid::Iec::Components::Code
- Inherits:
-
Components::Code
- Object
- Lutaml::Model::Serializable
- Components::Code
- Pubid::Iec::Components::Code
- Defined in:
- lib/pubid/iec/components/code.rb
Overview
Code component for IEC identifiers.
Inherits value and prefix from the shared Code; overrides rendering to place the prefix (e.g. “TR”, “TS”) before the value.
Class Method Summary collapse
-
.parse(string) ⇒ Object
Parse IEC code formats: - “60034” (just number) - “TR 61000” (with prefix) - “TS 62443” (with prefix).
Instance Method Summary collapse
- #to_s ⇒ Object (also: #full_code)
Methods inherited from Components::Code
Class Method Details
.parse(string) ⇒ Object
Parse IEC code formats:
-
“60034” (just number)
-
“TR 61000” (with prefix)
-
“TS 62443” (with prefix)
24 25 26 27 28 29 30 31 32 |
# File 'lib/pubid/iec/components/code.rb', line 24 def self.parse(string) parts = string.strip.split(" ", 2) if parts.size == 2 new(prefix: parts[0], value: parts[1]) else new(value: parts[0]) end end |
Instance Method Details
#to_s ⇒ Object Also known as: full_code
11 12 13 14 15 16 |
# File 'lib/pubid/iec/components/code.rb', line 11 def to_s result = "" result += "#{prefix} " if prefix result += value.to_s result end |