class YAHL7::V2::Scanner::IO

This scanner is responsible for scanning IO sources for HL7 messages. These IO sources can be StringIO, File, or anything else that is a Ruby IO.

Constants

MSG_HEADER
PREFIX

Public Class Methods

new(src) click to toggle source
# File lib/yahl7/v2/scanner/io.rb, line 13
def initialize(src)
  @source = src
  @message_regexp = /#{MSG_HEADER}\|/
  @buffer = StringIO.new
end

Public Instance Methods

each() { |msg| ... } click to toggle source
# File lib/yahl7/v2/scanner/io.rb, line 19
def each
  loop do
    msg = scan_next
    break if msg.nil?

    yield msg
  end
end
scan_next() click to toggle source
# File lib/yahl7/v2/scanner/io.rb, line 28
def scan_next
  return nil if @source.eof? && @buffer.length.zero?

  scan_message.strip
end

Private Instance Methods

read_message() click to toggle source
# File lib/yahl7/v2/scanner/io.rb, line 36
def read_message
  msg = @buffer.string
  @buffer = StringIO.new
  msg
end
scan_line() click to toggle source
# File lib/yahl7/v2/scanner/io.rb, line 42
def scan_line
  line = @source.readline(YAHL7::V2::SEGMENT_SEP)
  "#{line.strip}\r"
end
scan_message() click to toggle source
# File lib/yahl7/v2/scanner/io.rb, line 47
def scan_message
  loop do
    return read_message if @source.eof?

    line = scan_line

    if line[0..2] == MSG_HEADER && @buffer.length.positive?
      msg = read_message
      @buffer.write(line)
      return msg
    end

    @buffer.write(line)
  end
end