ruby-marc-spec 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.idea/marc-spec.iml +47 -47
- data/.ruby-version +1 -1
- data/.simplecov +3 -1
- data/CHANGES.md +7 -0
- data/LICENSE.md +1 -1
- data/README.md +18 -0
- data/lib/marc/spec/module_info.rb +1 -1
- data/lib/marc/spec/queries/query.rb +47 -9
- data/lib/marc/spec/queries/query_executor.rb +14 -11
- data/lib/marc/spec.rb +11 -1
- data/ruby-marc-spec.gemspec +1 -1
- data/spec/marc/spec_spec.rb +4 -0
- metadata +6 -6
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a7c07c75f4d7301b6a165724f8753630010c0df3b468b81c2debcc6ad38fb4d1
|
|
4
|
+
data.tar.gz: 36e1a57d33df1a5fe2553ec3fce562e08e58d2664c55262a644eeb49fecad4e4
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b08b4c373d701cf2e0a2e43c45fbb7081893f257437e7b8e6e6c4583e0cf4440869b3e25f0f31006f2c8be8a63953468ec39af8c94d9a03dc6bb1ccedbc4baef
|
|
7
|
+
data.tar.gz: b49627593b4e74361e443f4536145cc365d3ace763f87ee312263a968b65002f1696c389b14fc45376ac168950ae3293746f0435723080c98b51a26029931094
|
data/.idea/marc-spec.iml
CHANGED
|
@@ -6,53 +6,53 @@
|
|
|
6
6
|
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
|
7
7
|
<exclude-output />
|
|
8
8
|
<content url="file://$MODULE_DIR$" />
|
|
9
|
-
<orderEntry type="jdk" jdkName="RVM: ruby-2.7.
|
|
9
|
+
<orderEntry type="jdk" jdkName="RVM: ruby-2.7.5" jdkType="RUBY_SDK" />
|
|
10
10
|
<orderEntry type="sourceFolder" forTests="false" />
|
|
11
|
-
<orderEntry type="library" scope="PROVIDED" name="ast (v2.4.2, RVM: ruby-2.7.
|
|
12
|
-
<orderEntry type="library" scope="PROVIDED" name="builder (v3.2.4, RVM: ruby-2.7.
|
|
13
|
-
<orderEntry type="library" scope="PROVIDED" name="bundle-audit (v0.1.0, RVM: ruby-2.7.
|
|
14
|
-
<orderEntry type="library" scope="PROVIDED" name="bundler (v2.2.
|
|
15
|
-
<orderEntry type="library" scope="PROVIDED" name="bundler-audit (v0.9.0.1, RVM: ruby-2.7.
|
|
16
|
-
<orderEntry type="library" scope="PROVIDED" name="ci_reporter (v2.0.0, RVM: ruby-2.7.
|
|
17
|
-
<orderEntry type="library" scope="PROVIDED" name="ci_reporter_rspec (v1.0.0, RVM: ruby-2.7.
|
|
18
|
-
<orderEntry type="library" scope="PROVIDED" name="colorize (v0.8.1, RVM: ruby-2.7.
|
|
19
|
-
<orderEntry type="library" scope="PROVIDED" name="diff-lcs (v1.
|
|
20
|
-
<orderEntry type="library" scope="PROVIDED" name="docile (v1.4.0, RVM: ruby-2.7.
|
|
21
|
-
<orderEntry type="library" scope="PROVIDED" name="dotenv (v2.7.6, RVM: ruby-2.7.
|
|
22
|
-
<orderEntry type="library" scope="PROVIDED" name="ffi (v1.15.
|
|
23
|
-
<orderEntry type="library" scope="PROVIDED" name="io-console (v0.5.
|
|
24
|
-
<orderEntry type="library" scope="PROVIDED" name="irb (v1.
|
|
25
|
-
<orderEntry type="library" scope="PROVIDED" name="
|
|
26
|
-
<orderEntry type="library" scope="PROVIDED" name="
|
|
27
|
-
<orderEntry type="library" scope="PROVIDED" name="
|
|
28
|
-
<orderEntry type="library" scope="PROVIDED" name="
|
|
29
|
-
<orderEntry type="library" scope="PROVIDED" name="
|
|
30
|
-
<orderEntry type="library" scope="PROVIDED" name="
|
|
31
|
-
<orderEntry type="library" scope="PROVIDED" name="
|
|
32
|
-
<orderEntry type="library" scope="PROVIDED" name="
|
|
33
|
-
<orderEntry type="library" scope="PROVIDED" name="rb-
|
|
34
|
-
<orderEntry type="library" scope="PROVIDED" name="
|
|
35
|
-
<orderEntry type="library" scope="PROVIDED" name="
|
|
36
|
-
<orderEntry type="library" scope="PROVIDED" name="
|
|
37
|
-
<orderEntry type="library" scope="PROVIDED" name="
|
|
38
|
-
<orderEntry type="library" scope="PROVIDED" name="rspec (v3.10.
|
|
39
|
-
<orderEntry type="library" scope="PROVIDED" name="rspec-
|
|
40
|
-
<orderEntry type="library" scope="PROVIDED" name="rspec-
|
|
41
|
-
<orderEntry type="library" scope="PROVIDED" name="rspec-
|
|
42
|
-
<orderEntry type="library" scope="PROVIDED" name="
|
|
43
|
-
<orderEntry type="library" scope="PROVIDED" name="rubocop (v0.
|
|
44
|
-
<orderEntry type="library" scope="PROVIDED" name="
|
|
45
|
-
<orderEntry type="library" scope="PROVIDED" name="
|
|
46
|
-
<orderEntry type="library" scope="PROVIDED" name="
|
|
47
|
-
<orderEntry type="library" scope="PROVIDED" name="
|
|
48
|
-
<orderEntry type="library" scope="PROVIDED" name="simplecov (v0.
|
|
49
|
-
<orderEntry type="library" scope="PROVIDED" name="simplecov-
|
|
50
|
-
<orderEntry type="library" scope="PROVIDED" name="
|
|
51
|
-
<orderEntry type="library" scope="PROVIDED" name="thor (v1.1
|
|
52
|
-
<orderEntry type="library" scope="PROVIDED" name="typesafe_enum (v0.3.0, RVM: ruby-2.7.
|
|
53
|
-
<orderEntry type="library" scope="PROVIDED" name="unf (v0.1.4, RVM: ruby-2.7.
|
|
54
|
-
<orderEntry type="library" scope="PROVIDED" name="unf_ext (v0.0.8, RVM: ruby-2.7.
|
|
55
|
-
<orderEntry type="library" scope="PROVIDED" name="unicode-display_width (v1.8.0, RVM: ruby-2.7.
|
|
11
|
+
<orderEntry type="library" scope="PROVIDED" name="ast (v2.4.2, RVM: ruby-2.7.5) [gem]" level="application" />
|
|
12
|
+
<orderEntry type="library" scope="PROVIDED" name="builder (v3.2.4, RVM: ruby-2.7.5) [gem]" level="application" />
|
|
13
|
+
<orderEntry type="library" scope="PROVIDED" name="bundle-audit (v0.1.0, RVM: ruby-2.7.5) [gem]" level="application" />
|
|
14
|
+
<orderEntry type="library" scope="PROVIDED" name="bundler (v2.2.31, RVM: ruby-2.7.5) [gem]" level="application" />
|
|
15
|
+
<orderEntry type="library" scope="PROVIDED" name="bundler-audit (v0.9.0.1, RVM: ruby-2.7.5) [gem]" level="application" />
|
|
16
|
+
<orderEntry type="library" scope="PROVIDED" name="ci_reporter (v2.0.0, RVM: ruby-2.7.5) [gem]" level="application" />
|
|
17
|
+
<orderEntry type="library" scope="PROVIDED" name="ci_reporter_rspec (v1.0.0, RVM: ruby-2.7.5) [gem]" level="application" />
|
|
18
|
+
<orderEntry type="library" scope="PROVIDED" name="colorize (v0.8.1, RVM: ruby-2.7.5) [gem]" level="application" />
|
|
19
|
+
<orderEntry type="library" scope="PROVIDED" name="diff-lcs (v1.5.0, RVM: ruby-2.7.5) [gem]" level="application" />
|
|
20
|
+
<orderEntry type="library" scope="PROVIDED" name="docile (v1.4.0, RVM: ruby-2.7.5) [gem]" level="application" />
|
|
21
|
+
<orderEntry type="library" scope="PROVIDED" name="dotenv (v2.7.6, RVM: ruby-2.7.5) [gem]" level="application" />
|
|
22
|
+
<orderEntry type="library" scope="PROVIDED" name="ffi (v1.15.5, RVM: ruby-2.7.5) [gem]" level="application" />
|
|
23
|
+
<orderEntry type="library" scope="PROVIDED" name="io-console (v0.5.11, RVM: ruby-2.7.5) [gem]" level="application" />
|
|
24
|
+
<orderEntry type="library" scope="PROVIDED" name="irb (v1.4.1, RVM: ruby-2.7.5) [gem]" level="application" />
|
|
25
|
+
<orderEntry type="library" scope="PROVIDED" name="listen (v3.1.5, RVM: ruby-2.7.5) [gem]" level="application" />
|
|
26
|
+
<orderEntry type="library" scope="PROVIDED" name="marc (v1.1.1@335a02, RVM: ruby-2.7.5) [gem]" level="application" />
|
|
27
|
+
<orderEntry type="library" scope="PROVIDED" name="parallel (v1.21.0, RVM: ruby-2.7.5) [gem]" level="application" />
|
|
28
|
+
<orderEntry type="library" scope="PROVIDED" name="parser (v3.1.0.0, RVM: ruby-2.7.5) [gem]" level="application" />
|
|
29
|
+
<orderEntry type="library" scope="PROVIDED" name="parslet (v2.0.0, RVM: ruby-2.7.5) [gem]" level="application" />
|
|
30
|
+
<orderEntry type="library" scope="PROVIDED" name="rainbow (v3.1.1, RVM: ruby-2.7.5) [gem]" level="application" />
|
|
31
|
+
<orderEntry type="library" scope="PROVIDED" name="rake (v13.0.6, RVM: ruby-2.7.5) [gem]" level="application" />
|
|
32
|
+
<orderEntry type="library" scope="PROVIDED" name="rb-fsevent (v0.11.0, RVM: ruby-2.7.5) [gem]" level="application" />
|
|
33
|
+
<orderEntry type="library" scope="PROVIDED" name="rb-inotify (v0.10.1, RVM: ruby-2.7.5) [gem]" level="application" />
|
|
34
|
+
<orderEntry type="library" scope="PROVIDED" name="regexp_parser (v2.2.0, RVM: ruby-2.7.5) [gem]" level="application" />
|
|
35
|
+
<orderEntry type="library" scope="PROVIDED" name="reline (v0.3.1, RVM: ruby-2.7.5) [gem]" level="application" />
|
|
36
|
+
<orderEntry type="library" scope="PROVIDED" name="rexml (v3.2.5, RVM: ruby-2.7.5) [gem]" level="application" />
|
|
37
|
+
<orderEntry type="library" scope="PROVIDED" name="rspec (v3.10.0, RVM: ruby-2.7.5) [gem]" level="application" />
|
|
38
|
+
<orderEntry type="library" scope="PROVIDED" name="rspec-core (v3.10.2, RVM: ruby-2.7.5) [gem]" level="application" />
|
|
39
|
+
<orderEntry type="library" scope="PROVIDED" name="rspec-expectations (v3.10.2, RVM: ruby-2.7.5) [gem]" level="application" />
|
|
40
|
+
<orderEntry type="library" scope="PROVIDED" name="rspec-mocks (v3.10.3, RVM: ruby-2.7.5) [gem]" level="application" />
|
|
41
|
+
<orderEntry type="library" scope="PROVIDED" name="rspec-support (v3.10.3, RVM: ruby-2.7.5) [gem]" level="application" />
|
|
42
|
+
<orderEntry type="library" scope="PROVIDED" name="rubocop (v0.91.1, RVM: ruby-2.7.5) [gem]" level="application" />
|
|
43
|
+
<orderEntry type="library" scope="PROVIDED" name="rubocop-ast (v0.8.0, RVM: ruby-2.7.5) [gem]" level="application" />
|
|
44
|
+
<orderEntry type="library" scope="PROVIDED" name="ruby-progressbar (v1.11.0, RVM: ruby-2.7.5) [gem]" level="application" />
|
|
45
|
+
<orderEntry type="library" scope="PROVIDED" name="ruby_dep (v1.5.0, RVM: ruby-2.7.5) [gem]" level="application" />
|
|
46
|
+
<orderEntry type="library" scope="PROVIDED" name="scrub_rb (v1.0.1, RVM: ruby-2.7.5) [gem]" level="application" />
|
|
47
|
+
<orderEntry type="library" scope="PROVIDED" name="simplecov (v0.21.2, RVM: ruby-2.7.5) [gem]" level="application" />
|
|
48
|
+
<orderEntry type="library" scope="PROVIDED" name="simplecov-html (v0.12.3, RVM: ruby-2.7.5) [gem]" level="application" />
|
|
49
|
+
<orderEntry type="library" scope="PROVIDED" name="simplecov-rcov (v0.2.3, RVM: ruby-2.7.5) [gem]" level="application" />
|
|
50
|
+
<orderEntry type="library" scope="PROVIDED" name="simplecov_json_formatter (v0.1.3, RVM: ruby-2.7.5) [gem]" level="application" />
|
|
51
|
+
<orderEntry type="library" scope="PROVIDED" name="thor (v1.2.1, RVM: ruby-2.7.5) [gem]" level="application" />
|
|
52
|
+
<orderEntry type="library" scope="PROVIDED" name="typesafe_enum (v0.3.0, RVM: ruby-2.7.5) [gem]" level="application" />
|
|
53
|
+
<orderEntry type="library" scope="PROVIDED" name="unf (v0.1.4, RVM: ruby-2.7.5) [gem]" level="application" />
|
|
54
|
+
<orderEntry type="library" scope="PROVIDED" name="unf_ext (v0.0.8, RVM: ruby-2.7.5) [gem]" level="application" />
|
|
55
|
+
<orderEntry type="library" scope="PROVIDED" name="unicode-display_width (v1.8.0, RVM: ruby-2.7.5) [gem]" level="application" />
|
|
56
56
|
</component>
|
|
57
57
|
<component name="RModuleSettingsStorage">
|
|
58
58
|
<LOAD_PATH number="2" string0="$MODULE_DIR$/lib" string1="$MODULE_DIR$/spec" />
|
|
@@ -69,7 +69,7 @@
|
|
|
69
69
|
</RakeTaskImpl>
|
|
70
70
|
<RakeTaskImpl description="Run all specs in spec directory, with coverage" fullCommand="coverage" id="coverage" />
|
|
71
71
|
<RakeTaskImpl description="Run tests, check test coverage, check code style" fullCommand="default" id="default" />
|
|
72
|
-
<RakeTaskImpl description="Build ruby-marc-spec.gemspec as ruby-marc-spec-0.1.
|
|
72
|
+
<RakeTaskImpl description="Build ruby-marc-spec.gemspec as ruby-marc-spec-0.1.1.gem" fullCommand="gem" id="gem" />
|
|
73
73
|
<RakeTaskImpl description="Run RuboCop with auto-correct, and output results to console" fullCommand="ra" id="ra" />
|
|
74
74
|
<RakeTaskImpl description="Run rubocop with HTML output" fullCommand="rubocop" id="rubocop" />
|
|
75
75
|
<RakeTaskImpl id="rubocop">
|
data/.ruby-version
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
2.7
|
|
1
|
+
2.7.5
|
data/.simplecov
CHANGED
data/CHANGES.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
# 0.1.2 (2022-02-01)
|
|
2
|
+
|
|
3
|
+
- Adds `MARC::Spec#exists?` to check if a MARC record has data matching a
|
|
4
|
+
query, without actually retrieving the data. This is slightly more efficient
|
|
5
|
+
than using `MARC::Spec#find` with `any?`, as it will return early when it
|
|
6
|
+
finds the first result.
|
|
7
|
+
|
|
1
8
|
# 0.1.1 (2021-10-18)
|
|
2
9
|
|
|
3
10
|
- `MARC::Spec` methods now raise an `ArgumentError` for invalid query strings
|
data/LICENSE.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# The MIT License (MIT)
|
|
2
2
|
|
|
3
|
-
Copyright ©
|
|
3
|
+
Copyright © 2022 The Regents of the University of California
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a
|
|
6
6
|
copy of this software and associated documentation files (the “Software”),
|
data/README.md
CHANGED
|
@@ -170,3 +170,21 @@ MARC::Spec.find('260$b/0-7{$a~\San\sDiego}{050$b~008/7-10}', marc_record)
|
|
|
170
170
|
```
|
|
171
171
|
|
|
172
172
|
For further examples, see the MARCSpec [documentation](http://marcspec.github.io/MARCspec/marc-spec.html#marcspec-explained).
|
|
173
|
+
|
|
174
|
+
## For developers
|
|
175
|
+
|
|
176
|
+
### Generated tests
|
|
177
|
+
|
|
178
|
+
The tests for this gem include a set generated from the [MARCSpec-Test-Suite](https://github.com/MARCspec/MARCspec-Test-Suite)
|
|
179
|
+
project, which is provided as a [Git submodule](https://git-scm.com/book/en/v2/Git-Tools-Submodules)
|
|
180
|
+
under `spec/suite`.
|
|
181
|
+
|
|
182
|
+
The tests themselves are in [`spec/suite/generated`](spec/suite/generated). It's not necessary to fetch the submodule in order
|
|
183
|
+
to run these tests, but it is necessary if you need to regenerate them. To fetch the submodule, from the project root, run:
|
|
184
|
+
|
|
185
|
+
```sh
|
|
186
|
+
git submodule init
|
|
187
|
+
git submodule update
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
To regenerate the tests, run `rake spec:generate`.
|
|
@@ -7,7 +7,7 @@ module MARC
|
|
|
7
7
|
SUMMARY = 'MARCspec for Ruby'.freeze
|
|
8
8
|
DESCRIPTION = 'An implementation of the MARCspec query language for Ruby and ruby-marc'.freeze
|
|
9
9
|
LICENSE = 'MIT'.freeze
|
|
10
|
-
VERSION = '0.1.
|
|
10
|
+
VERSION = '0.1.2'.freeze
|
|
11
11
|
HOMEPAGE = 'https://github.com/BerkeleyLibrary/marc-spec'.freeze
|
|
12
12
|
end
|
|
13
13
|
end
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
require 'marc/spec/parsing/parser'
|
|
1
2
|
require 'marc/spec/queries/part'
|
|
2
3
|
|
|
3
4
|
module MARC
|
|
@@ -33,18 +34,17 @@ module MARC
|
|
|
33
34
|
|
|
34
35
|
# TODO: don't support nested subqueries
|
|
35
36
|
def execute(executor, context_fields, context_result = nil)
|
|
36
|
-
fields =
|
|
37
|
+
fields = tag_or_context_fields(executor, context_fields)
|
|
37
38
|
return [] if fields.empty?
|
|
38
39
|
|
|
39
|
-
field_results
|
|
40
|
-
|
|
40
|
+
field_results(executor, fields, context_result)
|
|
41
|
+
end
|
|
41
42
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
end
|
|
43
|
+
def any_results?(executor, context_fields, context_result = nil)
|
|
44
|
+
fields = tag_or_context_fields(executor, context_fields)
|
|
45
|
+
return false if fields.empty?
|
|
46
|
+
|
|
47
|
+
any_field_results?(executor, fields, context_result)
|
|
48
48
|
end
|
|
49
49
|
|
|
50
50
|
protected
|
|
@@ -66,6 +66,16 @@ module MARC
|
|
|
66
66
|
|
|
67
67
|
private
|
|
68
68
|
|
|
69
|
+
def tag_or_context_fields(executor, context_fields)
|
|
70
|
+
tag ? executor.apply_tag(tag) : context_fields
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def field_results(executor, fields, context_result)
|
|
74
|
+
return root_results(fields, executor, context_result) if subqueries.empty?
|
|
75
|
+
|
|
76
|
+
subquery_results(executor, fields)
|
|
77
|
+
end
|
|
78
|
+
|
|
69
79
|
def root_results(fields, executor, context_result)
|
|
70
80
|
field_results = results_for_fields(executor, fields)
|
|
71
81
|
# TODO: something less ridiculous
|
|
@@ -74,6 +84,19 @@ module MARC
|
|
|
74
84
|
selector.apply(context_result)
|
|
75
85
|
end
|
|
76
86
|
|
|
87
|
+
def subquery_results(executor, fields)
|
|
88
|
+
# NOTE: we do this one field at a time so that results are grouped
|
|
89
|
+
# by field, rather than by subfield code. Which isn't part of
|
|
90
|
+
# the MARCSpec spec, but it seems more in the spirit of MARC
|
|
91
|
+
# to preserve order wherever possible.
|
|
92
|
+
fields.each_with_object([]) do |field, results|
|
|
93
|
+
subqueries.each do |subquery|
|
|
94
|
+
subquery_results = subquery.execute(executor, [field])
|
|
95
|
+
results.concat(subquery_results)
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
|
|
77
100
|
def select_from_context?(context_result)
|
|
78
101
|
tag.nil? && context_result && selector.can_apply?(context_result)
|
|
79
102
|
end
|
|
@@ -92,6 +115,21 @@ module MARC
|
|
|
92
115
|
results.select { |result| executor.condition_met?(condition, field, result) }
|
|
93
116
|
end
|
|
94
117
|
|
|
118
|
+
def any_field_results?(executor, fields, context_result)
|
|
119
|
+
return any_root_results?(executor, fields, context_result) if subqueries.empty?
|
|
120
|
+
|
|
121
|
+
any_subfield_results?(executor, fields)
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
def any_root_results?(executor, fields, context_result)
|
|
125
|
+
root_results(fields, executor, context_result).any?
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
def any_subfield_results?(executor, fields)
|
|
129
|
+
fields.any? do |field|
|
|
130
|
+
subqueries.any? { |sq| sq.any_results?(executor, [field]) }
|
|
131
|
+
end
|
|
132
|
+
end
|
|
95
133
|
end
|
|
96
134
|
end
|
|
97
135
|
end
|
|
@@ -7,21 +7,30 @@ module MARC
|
|
|
7
7
|
class QueryExecutor
|
|
8
8
|
include Part
|
|
9
9
|
|
|
10
|
-
attr_reader :marc_record, :root_query
|
|
10
|
+
attr_reader :marc_record, :root_query
|
|
11
11
|
|
|
12
|
-
def initialize(marc_record,
|
|
12
|
+
def initialize(marc_record, root_query, cache = {})
|
|
13
13
|
@marc_record = ensure_type(marc_record, MARC::Record)
|
|
14
|
-
@root_query =
|
|
14
|
+
@root_query = root_query
|
|
15
15
|
@cache = cache
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def root_tag
|
|
19
|
+
@root_tag ||= root_query.tag || Tag.new('...')
|
|
20
|
+
end
|
|
16
21
|
|
|
17
|
-
|
|
18
|
-
@root_fields
|
|
22
|
+
def root_fields
|
|
23
|
+
@root_fields ||= apply_tag(root_tag)
|
|
19
24
|
end
|
|
20
25
|
|
|
21
26
|
def execute
|
|
22
27
|
root_query.execute(self, root_fields)
|
|
23
28
|
end
|
|
24
29
|
|
|
30
|
+
def any_results?
|
|
31
|
+
root_query.any_results?(self, root_fields)
|
|
32
|
+
end
|
|
33
|
+
|
|
25
34
|
def apply_tag(tag)
|
|
26
35
|
cache[tag] ||= tag.apply(marc_record)
|
|
27
36
|
end
|
|
@@ -40,12 +49,6 @@ module MARC
|
|
|
40
49
|
|
|
41
50
|
private
|
|
42
51
|
|
|
43
|
-
def as_query(root)
|
|
44
|
-
# TODO: unify these?
|
|
45
|
-
return root if root.is_a?(Query)
|
|
46
|
-
return Query.new(tag: root) if root.is_a?(Tag)
|
|
47
|
-
end
|
|
48
|
-
|
|
49
52
|
attr_reader :cache
|
|
50
53
|
end
|
|
51
54
|
end
|
data/lib/marc/spec.rb
CHANGED
|
@@ -9,6 +9,12 @@ module MARC
|
|
|
9
9
|
execute_query(root, marc_record)
|
|
10
10
|
end
|
|
11
11
|
|
|
12
|
+
def exists?(query_string, marc_record)
|
|
13
|
+
root = parse_query(query_string)
|
|
14
|
+
executor = executor_for(root, marc_record)
|
|
15
|
+
executor.any_results?
|
|
16
|
+
end
|
|
17
|
+
|
|
12
18
|
def parse_query(query_string)
|
|
13
19
|
parse_tree = parser.parse(query_string, reporter: reporter)
|
|
14
20
|
xform_result = xform.apply(parse_tree)
|
|
@@ -19,7 +25,7 @@ module MARC
|
|
|
19
25
|
end
|
|
20
26
|
|
|
21
27
|
def execute_query(query, marc_record)
|
|
22
|
-
executor =
|
|
28
|
+
executor = executor_for(query, marc_record)
|
|
23
29
|
executor.execute
|
|
24
30
|
end
|
|
25
31
|
|
|
@@ -36,6 +42,10 @@ module MARC
|
|
|
36
42
|
def reporter
|
|
37
43
|
@reporter ||= Parslet::ErrorReporter::Contextual.new
|
|
38
44
|
end
|
|
45
|
+
|
|
46
|
+
def executor_for(query, marc_record)
|
|
47
|
+
Queries::QueryExecutor.new(marc_record, query)
|
|
48
|
+
end
|
|
39
49
|
end
|
|
40
50
|
end
|
|
41
51
|
end
|
data/ruby-marc-spec.gemspec
CHANGED
|
@@ -37,6 +37,6 @@ Gem::Specification.new do |spec|
|
|
|
37
37
|
spec.add_development_dependency 'rake', '~> 13.0'
|
|
38
38
|
spec.add_development_dependency 'rspec', '~> 3.9'
|
|
39
39
|
spec.add_development_dependency 'rubocop', '~> 0.91.0'
|
|
40
|
-
spec.add_development_dependency 'simplecov', '~> 0.
|
|
40
|
+
spec.add_development_dependency 'simplecov', '~> 0.21.1'
|
|
41
41
|
spec.add_development_dependency 'simplecov-rcov', '~> 0.2'
|
|
42
42
|
end
|
data/spec/marc/spec_spec.rb
CHANGED
|
@@ -34,6 +34,10 @@ describe MARC::Spec do
|
|
|
34
34
|
expected = [expected] unless expected.is_a?(Array)
|
|
35
35
|
actual = MARC::Spec.find(query_str, marc_record)
|
|
36
36
|
expect(actual).to eq(expected), -> { failure_msg_for(query_str, actual, expected) }
|
|
37
|
+
|
|
38
|
+
should_exist = expected.any?
|
|
39
|
+
exists = MARC::Spec.exists?(query_str, marc_record)
|
|
40
|
+
expect(exists).to eq(should_exist), "Expected exists?(#{query_str.inspect}) to return #{should_exist}, was #{exists}"
|
|
37
41
|
end
|
|
38
42
|
end
|
|
39
43
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: ruby-marc-spec
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- David Moles
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2022-02-01 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: marc
|
|
@@ -190,14 +190,14 @@ dependencies:
|
|
|
190
190
|
requirements:
|
|
191
191
|
- - "~>"
|
|
192
192
|
- !ruby/object:Gem::Version
|
|
193
|
-
version: 0.
|
|
193
|
+
version: 0.21.1
|
|
194
194
|
type: :development
|
|
195
195
|
prerelease: false
|
|
196
196
|
version_requirements: !ruby/object:Gem::Requirement
|
|
197
197
|
requirements:
|
|
198
198
|
- - "~>"
|
|
199
199
|
- !ruby/object:Gem::Version
|
|
200
|
-
version: 0.
|
|
200
|
+
version: 0.21.1
|
|
201
201
|
- !ruby/object:Gem::Dependency
|
|
202
202
|
name: simplecov-rcov
|
|
203
203
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -327,14 +327,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
327
327
|
requirements:
|
|
328
328
|
- - ">="
|
|
329
329
|
- !ruby/object:Gem::Version
|
|
330
|
-
version:
|
|
330
|
+
version: 2.7.5
|
|
331
331
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
332
332
|
requirements:
|
|
333
333
|
- - ">="
|
|
334
334
|
- !ruby/object:Gem::Version
|
|
335
335
|
version: '0'
|
|
336
336
|
requirements: []
|
|
337
|
-
rubygems_version: 3.1.
|
|
337
|
+
rubygems_version: 3.1.6
|
|
338
338
|
signing_key:
|
|
339
339
|
specification_version: 4
|
|
340
340
|
summary: MARCspec for Ruby
|