Sha256: 0ca047b4944d745852ec821ce2281dfe6050fa2840a6b6ac0787bd2572efeb8f

Contents?: true

Size: 1012 Bytes

Versions: 11

Compression:

Stored size: 1012 Bytes

Contents

module Qa::Authorities
  module MeshTools
    class MeshDataParser

      attr_accessor :file

      def initialize(file)
        @file = file
      end

      def each_mesh_record(&block)
        current_data = {}
        in_record = false
        self.file.each_line do |line|
          case line
          when /\A\*NEWRECORD/
            yield(current_data) if in_record
            in_record = true
            current_data = {}
          when /\A(?<term>[^=]+) = (?<value>.*)/
            current_data[Regexp.last_match(:term)] ||= []
            current_data[Regexp.last_match(:term)] << Regexp.last_match(:value).strip
          when /\A\n/
            yield(current_data) if in_record
            in_record = false
          end
        end
        # final time in case file did not end with a blank line
        yield(current_data) if in_record
      end

      def all_records
        result = []
        self.each_mesh_record {|rec| result << rec }
        return result
      end

    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
qa-0.10.1 lib/qa/authorities/mesh_tools/mesh_data_parser.rb
qa-0.10.0 lib/qa/authorities/mesh_tools/mesh_data_parser.rb
qa-0.9.0 lib/qa/authorities/mesh_tools/mesh_data_parser.rb
qa-0.8.0 lib/qa/authorities/mesh_tools/mesh_data_parser.rb
qa-0.7.0 lib/qa/authorities/mesh_tools/mesh_data_parser.rb
qa-0.6.0 lib/qa/authorities/mesh_tools/mesh_data_parser.rb
qa-0.5.0 lib/qa/authorities/mesh_tools/mesh_data_parser.rb
qa-0.4.3 lib/qa/authorities/mesh_tools/mesh_data_parser.rb
qa-0.4.2 lib/qa/authorities/mesh_tools/mesh_data_parser.rb
qa-0.4.1 lib/qa/authorities/mesh_tools/mesh_data_parser.rb
qa-0.4.0 lib/qa/authorities/mesh_tools/mesh_data_parser.rb