lib/marc/spec.rb in ruby-marc-spec-0.1.0 vs lib/marc/spec.rb in ruby-marc-spec-0.1.1
- old
+ new
@@ -1,18 +1,27 @@
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)
- executor = Queries::QueryExecutor.new(marc_record, root)
- executor.execute
+ execute_query(root, marc_record)
end
def parse_query(query_string)
parse_tree = parser.parse(query_string, reporter: reporter)
- xform.apply(parse_tree)
+ 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