ruby-marc-spec 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f746cbe6bce86ac23cfc75c9b01c96c7127788af8ddffa81fa8e720bc015e3bd
4
- data.tar.gz: ff794cf138047fc798728671174c916069dba82da231cc0f306519cfba982772
3
+ metadata.gz: 54b13628142e544532fa38aff52eae04766e17c1bdfbfab6736c1ad1d6aa9a38
4
+ data.tar.gz: 498bd3f6ee88e2c41ef1ae95de9fabc1f5987d59944128f6853f54ec205168a8
5
5
  SHA512:
6
- metadata.gz: 328630cb81f72b2653b6bae02a16a957b0a1eeb55ae9be7b74eb79c68225046db0a937dbf09ebcf82f4529346849e5736462e1afc6c52b889ec32adec214e29c
7
- data.tar.gz: 6364636fdc30a08461f9636dd9cf99027f161a953487b64053a0c0a93feffc78236bc003f2973233a58d8947220d9bc1b1e694b08f9ef1b75b380cb17bc383ad
6
+ metadata.gz: 2c4cc664defc35600518fef9eb9ee1c8a3241b654cee78e114b8284399e965d9d4e09de4ea7232579198032b54a93543292d5c5cbc5697bfd10462b0ff4f816a
7
+ data.tar.gz: 0c8891024722e38dbc4a1f776f356b8d4411cb2f439f01904dad5b9ec8c0a12692147fb86805a38edea376fb8ac25d7159c75c5762f1e1b59fd492367539fe34
@@ -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 marc-spec.gemspec as marc-spec-0.1.0.gem" fullCommand="gem" id="gem" />
72
+ <RakeTaskImpl description="Build ruby-marc-spec.gemspec as ruby-marc-spec-0.1.0.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/.idea/modules.xml CHANGED
@@ -2,7 +2,7 @@
2
2
  <project version="4">
3
3
  <component name="ProjectModuleManager">
4
4
  <modules>
5
- <module fileurl="file://$PROJECT_DIR$/.idea/marc_spec.iml" filepath="$PROJECT_DIR$/.idea/marc_spec.iml" />
5
+ <module fileurl="file://$PROJECT_DIR$/.idea/marc-spec.iml" filepath="$PROJECT_DIR$/.idea/marc-spec.iml" />
6
6
  </modules>
7
7
  </component>
8
- </project>
8
+ </project>
data/CHANGES.md CHANGED
@@ -1,3 +1,18 @@
1
- # 0.1.0 (2021-03-15)
1
+ # 0.1.1 (2021-10-18)
2
+
3
+ - `MARC::Spec` methods now raise an `ArgumentError` for invalid query strings
4
+ instead of returning a raw `Parslet::ParseFailed`.
5
+ - Add `MARC::Spec#parse_query` and `MARC::Spec#execute_query` to facilitate
6
+ caching parsed query objects. (Not that parsing is expensive, but sometimes
7
+ it's convenient to be able to treat the query as a structured object rather
8
+ than a string.)
9
+ - Add `MARC::Spec::Queries::Query#tag_str` to retrieve the MARC tag specifier
10
+ from a query object. Note that this returns a MARCSpec `fieldTag` string
11
+ (which may include `.` wildcard characters), plus an optional, bracketed
12
+ `index`. For more information see
13
+ [9.2 Reference to field data](http://marcspec.github.io/MARCspec/marc-spec.html#reference-to-field-data)
14
+ in the MARCSpec docs.
15
+
16
+ # 0.1.0 (2021-10-15)
2
17
 
3
18
  - Initial release.
data/README.md CHANGED
@@ -1,5 +1,5 @@
1
1
  [![Build Status](https://github.com/BerkeleyLibrary/marc-spec/actions/workflows/build.yml/badge.svg?branch=main)](https://github.com/BerkeleyLibrary/marc-spec/actions/workflows/build.yml)
2
- [![Gem Version](https://img.shields.io/gem/v/ruby-marc-spec.svg)](https://github.com/ruby-marc-spec/releases)
2
+ [![Gem Version](https://img.shields.io/gem/v/ruby-marc-spec.svg)](https://rubygems.org/gems/ruby-marc-spec)
3
3
 
4
4
  # MARC::Spec
5
5
 
@@ -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.0'.freeze
10
+ VERSION = '0.1.1'.freeze
11
11
  HOMEPAGE = 'https://github.com/BerkeleyLibrary/marc-spec'.freeze
12
12
  end
13
13
  end
@@ -18,6 +18,10 @@ module MARC
18
18
  @subqueries = subqueries.map { |sq| ensure_type(sq, Query) }
19
19
  end
20
20
 
21
+ def tag_str
22
+ tag.to_s if tag
23
+ end
24
+
21
25
  def to_s
22
26
  StringIO.new.tap do |out|
23
27
  out << tag if tag
@@ -41,6 +41,7 @@ module MARC
41
41
  private
42
42
 
43
43
  def as_query(root)
44
+ # TODO: unify these?
44
45
  return root if root.is_a?(Query)
45
46
  return Query.new(tag: root) if root.is_a?(Tag)
46
47
  end
data/lib/marc/spec.rb CHANGED
@@ -3,15 +3,24 @@ Dir.glob(File.expand_path('spec/*.rb', __dir__)).sort.each(&method(:require))
3
3
  module MARC
4
4
  module Spec
5
5
  class << self
6
+
6
7
  def find(query_string, marc_record)
7
8
  root = parse_query(query_string)
8
- executor = Queries::QueryExecutor.new(marc_record, root)
9
- executor.execute
9
+ execute_query(root, marc_record)
10
10
  end
11
11
 
12
12
  def parse_query(query_string)
13
13
  parse_tree = parser.parse(query_string, reporter: reporter)
14
- xform.apply(parse_tree)
14
+ xform_result = xform.apply(parse_tree)
15
+ # TODO: unify these?
16
+ xform_result.is_a?(Queries::Query) ? xform_result : Queries::Query.new(tag: xform_result)
17
+ rescue Parslet::ParseFailed => e
18
+ raise ArgumentError, "Unable to parse query: #{query_string.inspect}: #{e}"
19
+ end
20
+
21
+ def execute_query(query, marc_record)
22
+ executor = Queries::QueryExecutor.new(marc_record, query)
23
+ executor.execute
15
24
  end
16
25
 
17
26
  private
@@ -25,13 +25,12 @@ module MARC::Spec
25
25
  aggregate_failures { examples.each { |query_str, expected| verify_result(query_str, expected) } }
26
26
  end
27
27
 
28
- def query_from(query_str)
29
- parse_tree = parser.parse(query_str)
30
- xform.apply(parse_tree)
28
+ def parse_query(query_str)
29
+ MARC::Spec.parse_query(query_str)
31
30
  end
32
31
 
33
32
  def verify_result(query_str, expected)
34
- query = query_from(query_str)
33
+ query = parse_query(query_str)
35
34
  executor = QueryExecutor.new(marc_record, query)
36
35
  actual = executor.execute
37
36
 
@@ -62,7 +61,7 @@ module MARC::Spec
62
61
  '245^1{=\\0}',
63
62
  '245$a{$b=\\t}$c$d'
64
63
  ].each do |query_str|
65
- query = query_from(query_str)
64
+ query = parse_query(query_str)
66
65
  str = query.to_s
67
66
  expect(str).not_to include('nil')
68
67
  all_elements = ([query.tag, query.selector] + query.subqueries).compact
@@ -73,6 +72,23 @@ module MARC::Spec
73
72
  end
74
73
  end
75
74
 
75
+ describe :tag_str do
76
+ it 'returns the tag' do
77
+ examples = {
78
+ '245$a{$b=\\t}$c$d' => '245',
79
+ '...$a$c' => '...',
80
+ '008/22{LDR/6=\b}' => '008',
81
+ '008[0]/3{/0=\a}' => '008[0]'
82
+ }
83
+ aggregate_failures do
84
+ examples.each do |query_str, expected|
85
+ query = parse_query(query_str)
86
+ expect(query.tag_str).to eq(expected)
87
+ end
88
+ end
89
+ end
90
+ end
91
+
76
92
  describe :to_s_inspect do
77
93
  it 'includes all elements' do
78
94
  # noinspection RubyLiteralArrayInspection
@@ -84,7 +100,7 @@ module MARC::Spec
84
100
  '245^1{=\\0}',
85
101
  '245$a{$b=\\t}$c$d'
86
102
  ].each do |query_str|
87
- query = query_from(query_str)
103
+ query = parse_query(query_str)
88
104
  inspect_str = query.inspect
89
105
  expect(inspect_str).not_to include('nil')
90
106
  all_elements = ([query.tag, query.selector] + query.subqueries).compact
@@ -38,6 +38,12 @@ describe MARC::Spec do
38
38
  end
39
39
  end
40
40
 
41
+ describe :parse_query do
42
+ it 'raises ArgumentError for an invalid query' do
43
+ expect { MARC::Spec.parse_query('not a query') }.to raise_error(ArgumentError)
44
+ end
45
+ end
46
+
41
47
  describe 'non-repeated subfields' do
42
48
  before(:each) do
43
49
  @marc_record = MARC::XMLReader.new('spec/data/sandburg.xml').first
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.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Moles
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-10-16 00:00:00.000000000 Z
11
+ date: 2021-10-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: marc
@@ -224,7 +224,7 @@ files:
224
224
  - ".idea/codeStyles/codeStyleConfig.xml"
225
225
  - ".idea/go.imports.xml"
226
226
  - ".idea/inspectionProfiles/Project_Default.xml"
227
- - ".idea/marc_spec.iml"
227
+ - ".idea/marc-spec.iml"
228
228
  - ".idea/misc.xml"
229
229
  - ".idea/modules.xml"
230
230
  - ".idea/templateLanguages.xml"
@@ -312,7 +312,7 @@ files:
312
312
  - spec/marc/spec/queries/subfield_value_spec.rb
313
313
  - spec/marc/spec/queries/tag_spec.rb
314
314
  - spec/marc/spec/queries/transform_spec.rb
315
- - spec/marc_spec_spec.rb
315
+ - spec/marc/spec_spec.rb
316
316
  - spec/scratch_spec.rb
317
317
  - spec/spec_helper.rb
318
318
  homepage: https://github.com/BerkeleyLibrary/marc-spec