class Hippo_eyeDoc::Parser

Public Class Methods

new() click to toggle source
# File lib/hippo_eyeDoc/parser.rb, line 19
def initialize
  super
end
parse_file(input) click to toggle source
# File lib/hippo_eyeDoc/parser.rb, line 9
def self.parse_file(input)
  parser = new
  parser.parse_string(input)
end
parse_string(input) click to toggle source
# File lib/hippo_eyeDoc/parser.rb, line 14
def self.parse_string(input)
  parser = new
  parser.parse_string(input)
end

Public Instance Methods

initialize_transaction_set(index) click to toggle source
# File lib/hippo_eyeDoc/parser.rb, line 23
def initialize_transaction_set(index)
  {
    :segments  => [],
    :ISA       => find_first_segment(parsed_segments[0,index + 1], 'ISA', true),
    :GS        => find_first_segment(parsed_segments[0,index + 1], 'GS', true),
    :GE        => find_first_segment(parsed_segments[index + 1, parsed_segments.length - index + 1], 'GE'),
    :IEA       => find_first_segment(parsed_segments[index + 1, parsed_segments.length - index + 1], 'IEA')
  }
end
parse_file(filename) click to toggle source
# File lib/hippo_eyeDoc/parser.rb, line 61
def parse_file(filename)
  parse_string(File.read(filename))
end
parse_string(input) click to toggle source
# File lib/hippo_eyeDoc/parser.rb, line 65
def parse_string(input)
  read(input)
  populate_transaction_sets
end
parse_transaction_sets() click to toggle source
# File lib/hippo_eyeDoc/parser.rb, line 33
def parse_transaction_sets
  raw_transaction_sets  = []
  inside_transaction    = false

  parsed_segments.each_with_index do |segment, index|
    if segment.identifier == 'ST'
      raw_transaction_sets << initialize_transaction_set(index)

      inside_transaction = true
    end

    raw_transaction_sets.last[:segments] << segment if inside_transaction

    inside_transaction = false if segment.identifier == 'SE'
  end

  raw_transaction_sets
end
populate_transaction_sets() click to toggle source
# File lib/hippo_eyeDoc/parser.rb, line 52
def populate_transaction_sets
  parse_transaction_sets.collect do |transaction|
    transaction_set_id = transaction[:segments].first.ST01
    transaction_set = Hippo_eyeDoc::TransactionSets.constants.select{|c| c.to_s.end_with?(transaction_set_id) }.first

    Hippo_eyeDoc::TransactionSets.const_get(transaction_set)::Base.new(separators.merge(transaction))
  end
end