Class: Pubid::Iec::Components::Code

Inherits:
Components::Code
  • Object
show all
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

Instance Method Summary collapse

Methods inherited from Components::Code

#eql?, #hash, #render

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_sObject 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