class YAHL7::V2::Scanner::String

This scanner is responsible for parsing string sources for HL7 files. This adds some flexibility to the program, so we don't have to always parse IO sources. This allows us to accept HL7 data through a web form, for example.

Constants

MSG_HEADER
PREFIX

Public Class Methods

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

Public Instance Methods

each() { |msg| ... } click to toggle source
# File lib/yahl7/v2/scanner/string.rb, line 20
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/string.rb, line 29
def scan_next
  return nil if @scanner.eos?

  scan_message.strip
end

Private Instance Methods

scan_message() click to toggle source
# File lib/yahl7/v2/scanner/string.rb, line 37
def scan_message
  got = @scanner.scan_until(@message_regexp)
  got = @scanner.scan_until(@message_regexp) if got == PREFIX

  if got.nil?
    got = @scanner.rest
    @scanner.terminate
  end

  got = got.lstrip.delete_suffix(PREFIX)
  got.start_with?(PREFIX) ? got : PREFIX + got
end