Class: SimpleHL7::Subcomponent

Inherits:
Object
  • Object
show all
Defined in:
lib/simple_hl7/subcomponent.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value) ⇒ Subcomponent

Returns a new instance of Subcomponent.



5
6
7
# File 'lib/simple_hl7/subcomponent.rb', line 5

def initialize(value)
  @value = value.nil? ? '' : value
end

Instance Attribute Details

#valueObject

Returns the value of attribute value.



3
4
5
# File 'lib/simple_hl7/subcomponent.rb', line 3

def value
  @value
end

Class Method Details

.parse(str, separator_chars) ⇒ Object



23
24
25
26
27
28
29
30
31
# File 'lib/simple_hl7/subcomponent.rb', line 23

def self.parse(str, separator_chars)
  value = str
  value.gsub!("\\E\\", separator_chars.escape)
  value.gsub!("\\F\\", separator_chars.field)
  value.gsub!("\\R\\", separator_chars.repetition)
  value.gsub!("\\S\\", separator_chars.component)
  value.gsub!("\\T\\", separator_chars.subcomponent)
  Subcomponent.new(value)
end

Instance Method Details

#to_hl7(separator_chars) ⇒ Object



9
10
11
12
13
14
15
16
17
# File 'lib/simple_hl7/subcomponent.rb', line 9

def to_hl7(separator_chars)
  hl7 = value
  hl7.gsub!(separator_chars.escape, "\\E\\")
  hl7.gsub!(separator_chars.field, "\\F\\")
  hl7.gsub!(separator_chars.repetition, "\\R\\")
  hl7.gsub!(separator_chars.component, "\\S\\")
  hl7.gsub!(separator_chars.subcomponent, "\\T\\")
  hl7
end

#to_sObject



19
20
21
# File 'lib/simple_hl7/subcomponent.rb', line 19

def to_s
  value
end