Sha256: a3e626c1b976a368d57690ce67f1001d8a44952b5e1b080d2973e6d42972b0ec

Contents?: true

Size: 1.06 KB

Versions: 5

Compression:

Stored size: 1.06 KB

Contents

module Qa::Authorities
  module MeshTools
    class MeshDataParser
      attr_accessor :file

      def initialize(file)
        @file = file
      end

      # rubocop:disable Metrics/MethodLength
      # rubocop:disable Metrics/CyclomaticComplexity
      def each_mesh_record
        current_data = {}
        in_record = false
        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 = []
        each_mesh_record { |rec| result << rec }
        result
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
qa-5.13.0 lib/qa/authorities/mesh_tools/mesh_data_parser.rb
qa-5.12.0 lib/qa/authorities/mesh_tools/mesh_data_parser.rb
qa-5.11.0 lib/qa/authorities/mesh_tools/mesh_data_parser.rb
qa-5.10.0 lib/qa/authorities/mesh_tools/mesh_data_parser.rb
qa-5.9.0 lib/qa/authorities/mesh_tools/mesh_data_parser.rb