marcspec 0.7.1 → 0.7.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.
- data/CHANGES +3 -1
- data/VERSION +1 -1
- data/lib/marcspec/customspec.rb +6 -6
- data/lib/marcspec.rb +22 -1
- data/spec/solrfieldspec_spec.rb +4 -4
- data/spec/specset_spec.rb +1 -1
- metadata +3 -3
data/CHANGES
CHANGED
@@ -1,5 +1,7 @@
|
|
1
|
+
0.7.2
|
2
|
+
* Also change methodArgs to functionArgs
|
1
3
|
0.7.1
|
2
|
-
* Forgot to update this CHANGES file.
|
4
|
+
* Forgot to update this CHANGES file.
|
3
5
|
0.7.0
|
4
6
|
* Change configuration for custom functions to use :functionSymbol instead of :methodSymbol. Because, you know, they're
|
5
7
|
module functions, not class methods.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.7.
|
1
|
+
0.7.2
|
data/lib/marcspec/customspec.rb
CHANGED
@@ -32,7 +32,7 @@ module MARCSpec
|
|
32
32
|
|
33
33
|
class CustomSolrSpec < SolrFieldSpec
|
34
34
|
|
35
|
-
attr_accessor :module, :functionSymbol, :
|
35
|
+
attr_accessor :module, :functionSymbol, :functionArgs
|
36
36
|
|
37
37
|
# Get a new Custom Solr Spec based on the passed in options.
|
38
38
|
# @param [Hash] opts Initialization options
|
@@ -58,7 +58,7 @@ module MARCSpec
|
|
58
58
|
end
|
59
59
|
|
60
60
|
|
61
|
-
@
|
61
|
+
@functionArgs = opts[:functionArgs] || []
|
62
62
|
|
63
63
|
@first = opts[:firstOnly] || false
|
64
64
|
@default = opts[:default] || nil
|
@@ -86,7 +86,7 @@ module MARCSpec
|
|
86
86
|
# @return [Array<String>] An array of values returned by the custom method
|
87
87
|
|
88
88
|
def raw_marc_values r, doc
|
89
|
-
return @module.send(@functionSymbol, doc, r, *@
|
89
|
+
return @module.send(@functionSymbol, doc, r, *@functionArgs)
|
90
90
|
end
|
91
91
|
|
92
92
|
|
@@ -121,9 +121,9 @@ module MARCSpec
|
|
121
121
|
PP.singleline_pp(@module, s)
|
122
122
|
s.print(",\n :functionSymbol => ")
|
123
123
|
PP.singleline_pp(@functionSymbol, s)
|
124
|
-
if @
|
125
|
-
s.print(",\n :
|
126
|
-
PP.singleline_pp(@
|
124
|
+
if @functionArgs
|
125
|
+
s.print(",\n :functionArgs => ")
|
126
|
+
PP.singleline_pp(@functionArgs, s)
|
127
127
|
end
|
128
128
|
s.print "\n}"
|
129
129
|
return s.string
|
data/lib/marcspec.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'logger'
|
2
|
+
require 'marc4j4r'
|
2
3
|
|
3
4
|
$LOG = Logger.new(STDOUT)
|
4
5
|
$LOG.level = Logger::WARN
|
@@ -8,4 +9,24 @@ require "marcspec/solrfieldspec"
|
|
8
9
|
require "marcspec/kvmap"
|
9
10
|
require "marcspec/multivaluemap"
|
10
11
|
require "marcspec/specset"
|
11
|
-
require "marcspec/marcfieldspec"
|
12
|
+
require "marcspec/marcfieldspec"
|
13
|
+
|
14
|
+
|
15
|
+
# Build up a little module to include in MARC4J4R::Record that
|
16
|
+
# gives us a way to cache computed values within the record itself
|
17
|
+
# It's just a hash.
|
18
|
+
|
19
|
+
module CacheSpot
|
20
|
+
def cacheadd k, v
|
21
|
+
@_cachespot ||= {}
|
22
|
+
@_cachespot[k] = v
|
23
|
+
return v
|
24
|
+
end
|
25
|
+
|
26
|
+
def cacheget k
|
27
|
+
@_cachespot ||= {}
|
28
|
+
return @_cachespot[k]
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
MARC4J4R::Record.send(:include, CacheSpot)
|
data/spec/solrfieldspec_spec.rb
CHANGED
@@ -170,24 +170,24 @@ describe "CustomSolrSpec" do
|
|
170
170
|
end
|
171
171
|
|
172
172
|
it "accepts nil for no args" do
|
173
|
-
css = MARCSpec::CustomSolrSpec.new(:solrField=>'solrField', :module=>A::B, :functionSymbol=>:titleUp, :
|
173
|
+
css = MARCSpec::CustomSolrSpec.new(:solrField=>'solrField', :module=>A::B, :functionSymbol=>:titleUp, :functionArgs=>nil)
|
174
174
|
css.marc_values(@one).should.equal [@one['245'].value.upcase]
|
175
175
|
end
|
176
176
|
|
177
177
|
|
178
178
|
it "uses a custom method with args but no map" do
|
179
|
-
css = MARCSpec::CustomSolrSpec.new(:solrField=>'solrField', :module=>A::B, :functionSymbol=>:titleUp, :
|
179
|
+
css = MARCSpec::CustomSolrSpec.new(:solrField=>'solrField', :module=>A::B, :functionSymbol=>:titleUp, :functionArgs=>[['a', 'c']])
|
180
180
|
css.marc_values(@one).should.equal [@titleACValue.upcase]
|
181
181
|
end
|
182
182
|
|
183
183
|
it "works with a map" do
|
184
|
-
css = MARCSpec::CustomSolrSpec.new(:solrField=>'solrField', :map=>@map, :module=>A::B, :functionSymbol=>:titleUp, :
|
184
|
+
css = MARCSpec::CustomSolrSpec.new(:solrField=>'solrField', :map=>@map, :module=>A::B, :functionSymbol=>:titleUp, :functionArgs=>[['a', 'c']])
|
185
185
|
css.marc_values(@one).should.equal [@mapValue]
|
186
186
|
end
|
187
187
|
|
188
188
|
it "works with a map that has multiple return values" do
|
189
189
|
@map[@titleACValue.upcase] = ['two', 'one']
|
190
|
-
css = MARCSpec::CustomSolrSpec.new(:solrField=>'solrField', :map=>@map, :module=>A::B, :functionSymbol=>:titleUp, :
|
190
|
+
css = MARCSpec::CustomSolrSpec.new(:solrField=>'solrField', :map=>@map, :module=>A::B, :functionSymbol=>:titleUp, :functionArgs=>[['a', 'c']])
|
191
191
|
css.marc_values(@one).should.equal ['two', 'one']
|
192
192
|
end
|
193
193
|
|
data/spec/specset_spec.rb
CHANGED
@@ -65,7 +65,7 @@ describe "SpecSet Basics" do
|
|
65
65
|
end
|
66
66
|
|
67
67
|
it "allows customs that reference previous work" do
|
68
|
-
@speclist << {:solrField=>'titleSort', :module=>A::B, :functionSymbol=>:sortable, :
|
68
|
+
@speclist << {:solrField=>'titleSort', :module=>A::B, :functionSymbol=>:sortable, :functionArgs=>['title']}
|
69
69
|
ss = MARCSpec::SpecSet.new
|
70
70
|
ss.buildSpecsFromList(@speclist)
|
71
71
|
h = ss.hash_from_marc @one
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: marcspec
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 7
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 7
|
9
|
-
-
|
10
|
-
version: 0.7.
|
9
|
+
- 2
|
10
|
+
version: 0.7.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- BillDueber
|