Sha256: b02ba12dd2b4cbd2c3ff240039f7e02027049db45bb9529699731aa6dc235178

Contents?: true

Size: 1.05 KB

Versions: 1

Compression:

Stored size: 1.05 KB

Contents

Dir.glob(File.expand_path('spec/*.rb', __dir__)).sort.each(&method(:require))

module MARC
  module Spec
    class << self

      def find(query_string, marc_record)
        root = parse_query(query_string)
        execute_query(root, marc_record)
      end

      def parse_query(query_string)
        parse_tree = parser.parse(query_string, reporter: reporter)
        xform_result = xform.apply(parse_tree)
        # TODO: unify these?
        xform_result.is_a?(Queries::Query) ? xform_result : Queries::Query.new(tag: xform_result)
      rescue Parslet::ParseFailed => e
        raise ArgumentError, "Unable to parse query: #{query_string.inspect}: #{e}"
      end

      def execute_query(query, marc_record)
        executor = Queries::QueryExecutor.new(marc_record, query)
        executor.execute
      end

      private

      def parser
        @parser ||= Parsing::Parser.new
      end

      def xform
        @xform ||= Queries::Transform.new
      end

      def reporter
        @reporter ||= Parslet::ErrorReporter::Contextual.new
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ruby-marc-spec-0.1.1 lib/marc/spec.rb