Class: HL7::MessageParser

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

Overview

Provides basic methods to parse_string, element and item delimeter parser

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(delimiter) ⇒ MessageParser

Returns a new instance of MessageParser.



55
56
57
# File 'lib/message_parser.rb', line 55

def initialize(delimiter)
  @delimiter = delimiter
end

Instance Attribute Details

#delimiterObject (readonly)

Returns the value of attribute delimiter.



49
50
51
# File 'lib/message_parser.rb', line 49

def delimiter
  @delimiter
end

Class Method Details

.split_by_delimiter(element, delimiter) ⇒ Object



51
52
53
# File 'lib/message_parser.rb', line 51

def self.split_by_delimiter(element, delimiter)
  element.split(delimiter, -1)
end

Instance Method Details

#parse_element_delim(str) ⇒ Object

Get the element delimiter from an MSH segment



69
70
71
# File 'lib/message_parser.rb', line 69

def parse_element_delim(str)
  str.is_a?(String) ? str.slice(3, 1) : "|"
end

#parse_item_delim(str) ⇒ Object

Get the item delimiter from an MSH segment



74
75
76
# File 'lib/message_parser.rb', line 74

def parse_item_delim(str)
  str.is_a?(String) ? str.slice(4, 1) : "^"
end

#parse_string(instr) ⇒ Object

parse the provided String or Enumerable object into this message



60
61
62
63
64
65
66
# File 'lib/message_parser.rb', line 60

def parse_string(instr)
  post_mllp = instr
  if /\x0b((:?.|\r|\n)+)\x1c\r/ =~ instr
    post_mllp = $1 # strip the mllp bytes
  end
  HL7::MessageParser.split_by_delimiter(post_mllp, @delimiter.segment)
end