marcspec 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +21 -0
- data/LICENSE +20 -0
- data/README.rdoc +59 -0
- data/Rakefile +58 -0
- data/VERSION +1 -0
- data/lib/marcspec/customspec.rb +97 -0
- data/lib/marcspec/kvmap.rb +79 -0
- data/lib/marcspec/map.rb +67 -0
- data/lib/marcspec/marcfieldspec.rb +205 -0
- data/lib/marcspec/multivaluemap.rb +62 -0
- data/lib/marcspec/solrfieldspec.rb +123 -0
- data/lib/marcspec/specset.rb +58 -0
- data/lib/marcspec.rb +11 -0
- data/lib/orig.rb +288 -0
- data/spec/data/batch.dat +1 -0
- data/spec/data/one.dat +1 -0
- data/spec/data/umich/translation_maps/area_map.properties +1039 -0
- data/spec/data/umich/translation_maps/availability_map_ht.properties +9 -0
- data/spec/data/umich/translation_maps/availability_map_umich.properties +6 -0
- data/spec/data/umich/translation_maps/callnumber_map.properties +21 -0
- data/spec/data/umich/translation_maps/callnumber_subject_map.properties +214 -0
- data/spec/data/umich/translation_maps/country_map.properties +320 -0
- data/spec/data/umich/translation_maps/format_map.properties +47 -0
- data/spec/data/umich/translation_maps/format_map_umich.properties +35 -0
- data/spec/data/umich/translation_maps/ht_namespace_map.properties +10 -0
- data/spec/data/umich/translation_maps/institution_map.properties +11 -0
- data/spec/data/umich/translation_maps/language_map.properties +489 -0
- data/spec/data/umich/translation_maps/library_map.properties +48 -0
- data/spec/data/umich/translation_maps/location_map.properties +345 -0
- data/spec/data/umich/umich_index.properties +130 -0
- data/spec/maps_spec.rb +91 -0
- data/spec/marcfieldspecs_spec.rb +109 -0
- data/spec/marcspec_spec.rb +10 -0
- data/spec/solrfieldspec_spec.rb +177 -0
- data/spec/spec_helper.rb +16 -0
- metadata +166 -0
@@ -0,0 +1,177 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "SolrFieldSpec" do
|
4
|
+
before do
|
5
|
+
@one = MARC4J4R::Reader.new("#{DIR}/data/one.dat").first
|
6
|
+
# @batch = MARC4J4R::Reader.new("#{DIR}/batch.dat").collect
|
7
|
+
@opts = {:solrField=>'solrfield'}
|
8
|
+
@titleAC = MARCSpec::VariableFieldSpec.new('245', ['a', 'c'])
|
9
|
+
@titleACValue = "The Texas ranger Sung by Beale D. Taylor."
|
10
|
+
@twosixtyC = MARCSpec::VariableFieldSpec.new('260', 'c')
|
11
|
+
@twosixtyCValue = "1939."
|
12
|
+
|
13
|
+
@nonmatchingSpec = MARCSpec::VariableFieldSpec.new('999', ['a', 'c'])
|
14
|
+
|
15
|
+
@default = 'DEFAULT'
|
16
|
+
|
17
|
+
|
18
|
+
@mapValue = "twosixtyCMapValue"
|
19
|
+
@mapValueForDefault = 'mapValueForDefaultValue'
|
20
|
+
@noMapKeyDefault = 'noMapKeyDefault'
|
21
|
+
|
22
|
+
@map = MARCSpec::KVMap.new('nameOfTheMap', {@twosixtyCValue => @mapValue, @default=>@mapValueForDefault})
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
it "works with a single fieldspec" do
|
27
|
+
sfs = MARCSpec::SolrFieldSpec.new(@opts)
|
28
|
+
sfs << @titleAC
|
29
|
+
sfs.marc_values(@one).should.equal [@titleACValue]
|
30
|
+
end
|
31
|
+
|
32
|
+
|
33
|
+
it "works with a double fieldspec" do
|
34
|
+
sfs = MARCSpec::SolrFieldSpec.new(@opts)
|
35
|
+
sfs << @titleAC
|
36
|
+
sfs << @twosixtyC
|
37
|
+
sfs.marc_values(@one).should.equal [@titleACValue, @twosixtyCValue]
|
38
|
+
end
|
39
|
+
|
40
|
+
it "preserves order" do
|
41
|
+
sfs = MARCSpec::SolrFieldSpec.new(@opts)
|
42
|
+
sfs << @twosixtyC
|
43
|
+
sfs << @titleAC
|
44
|
+
sfs.marc_values(@one).should.equal [@twosixtyCValue, @titleACValue]
|
45
|
+
end
|
46
|
+
|
47
|
+
|
48
|
+
it "works with firstOnly" do
|
49
|
+
@opts[:firstOnly] = true
|
50
|
+
sfs = MARCSpec::SolrFieldSpec.new(@opts)
|
51
|
+
sfs << @titleAC
|
52
|
+
sfs << @twosixtyC
|
53
|
+
sfs.marc_values(@one).should.equal [@titleACValue]
|
54
|
+
end
|
55
|
+
|
56
|
+
it "returns nothing where there are no matches" do
|
57
|
+
sfs = MARCSpec::SolrFieldSpec.new(@opts)
|
58
|
+
sfs << @nonmatchingSpec
|
59
|
+
sfs.marc_values(@one).should.equal []
|
60
|
+
end
|
61
|
+
|
62
|
+
it "works with a default" do
|
63
|
+
@opts[:default] = @default
|
64
|
+
sfs = MARCSpec::SolrFieldSpec.new(@opts)
|
65
|
+
sfs << @nonmatchingSpec
|
66
|
+
sfs.marc_values(@one).should.equal [@default]
|
67
|
+
end
|
68
|
+
|
69
|
+
it "works with a KV Map and no defaults" do
|
70
|
+
@opts[:map] = @map
|
71
|
+
sfs = MARCSpec::SolrFieldSpec.new(@opts)
|
72
|
+
sfs << @titleAC
|
73
|
+
sfs << @twosixtyC
|
74
|
+
sfs.marc_values(@one).should.equal [@mapValue]
|
75
|
+
end
|
76
|
+
|
77
|
+
it "works with a KV Map and just a map default" do
|
78
|
+
@opts[:map] = @map
|
79
|
+
@opts[:noMapKeyDefault] = @noMapKeyDefault
|
80
|
+
sfs = MARCSpec::SolrFieldSpec.new(@opts)
|
81
|
+
sfs << @titleAC # not in map, get noMapKeyDefault
|
82
|
+
sfs << @twosixtyC # in map, get mapValue
|
83
|
+
sfs.marc_values(@one).should.equal [@noMapKeyDefault, @mapValue]
|
84
|
+
end
|
85
|
+
|
86
|
+
it "works with a KV Map and returns default value correctly" do
|
87
|
+
@opts[:map] = @map
|
88
|
+
@opts[:default] = @default
|
89
|
+
@opts[:noMapKeyDefault] = @noMapKeyDefault
|
90
|
+
sfs = MARCSpec::SolrFieldSpec.new(@opts)
|
91
|
+
sfs << @nonmatchingSpec
|
92
|
+
sfs.marc_values(@one).should.equal [@default]
|
93
|
+
end
|
94
|
+
|
95
|
+
it "returns multiple values from a kv map when appropriate" do
|
96
|
+
@map[@twosixtyCValue] = ['one', 'two']
|
97
|
+
@opts[:map] = @map
|
98
|
+
sfs = MARCSpec::SolrFieldSpec.new(@opts)
|
99
|
+
sfs << @twosixtyC
|
100
|
+
sfs.marc_values(@one).sort.should.equal ['one', 'two']
|
101
|
+
end
|
102
|
+
|
103
|
+
it "flattens things out when getting multiple values from a kv map" do
|
104
|
+
@map[@titleACValue] = ['one', 'two']
|
105
|
+
@map[@twosixtyCValue] = ['three', 'four']
|
106
|
+
@opts[:map] = @map
|
107
|
+
sfs = MARCSpec::SolrFieldSpec.new(@opts)
|
108
|
+
sfs << @twosixtyC
|
109
|
+
sfs << @titleAC
|
110
|
+
sfs.marc_values(@one).sort.should.equal ['one', 'two', 'three', 'four'].sort
|
111
|
+
end
|
112
|
+
|
113
|
+
|
114
|
+
it "round trips if you add the map by hand" do
|
115
|
+
@opts[:map] = @map
|
116
|
+
@opts[:noMapKeyDefault] = @noMapKeyDefault
|
117
|
+
sfs = MARCSpec::SolrFieldSpec.new(@opts)
|
118
|
+
sfs << @titleAC # not in map, get noMapKeyDefault
|
119
|
+
sfs << @twosixtyC # in map, get mapValue
|
120
|
+
|
121
|
+
newsfs = MARCSpec::SolrFieldSpec.fromPPString(sfs.asPPString)
|
122
|
+
newsfs.map = @map
|
123
|
+
sfs.should.equal newsfs
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
module A
|
128
|
+
module B
|
129
|
+
def self.titleUp r, codes=nil
|
130
|
+
title = r['245']
|
131
|
+
if codes
|
132
|
+
return [title.sub_values(codes).join(' ').upcase]
|
133
|
+
else
|
134
|
+
return [title.value.upcase]
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
|
141
|
+
|
142
|
+
describe "CustomSolrSpec" do
|
143
|
+
before do
|
144
|
+
@one = MARC4J4R::Reader.new("#{DIR}/data/one.dat").first
|
145
|
+
@opts = {:solrField=>'solrfield'}
|
146
|
+
@titleACValue = "The Texas ranger Sung by Beale D. Taylor."
|
147
|
+
@twosixtyCValue = "1939."
|
148
|
+
@mapValue = "titleACUppercaseValue"
|
149
|
+
@mapValueForDefault = 'mapValueForDefaultValue'
|
150
|
+
@noMapKeyDefault = 'noMapKeyDefault'
|
151
|
+
|
152
|
+
@map = MARCSpec::KVMap.new('nameOfTheMap', {@titleACValue.upcase => @mapValue, @default=>@mapValueForDefault})
|
153
|
+
end
|
154
|
+
|
155
|
+
it "works with no args or map" do
|
156
|
+
css = MARCSpec::CustomSolrSpec.new(:solrField=>'solrField', :module=>A::B, :methodSymbol=>:titleUp)
|
157
|
+
css.marc_values(@one).should.equal [@one['245'].value.upcase]
|
158
|
+
end
|
159
|
+
|
160
|
+
it "accepts nil for no args" do
|
161
|
+
css = MARCSpec::CustomSolrSpec.new(:solrField=>'solrField', :module=>A::B, :methodSymbol=>:titleUp, :methodArgs=>nil)
|
162
|
+
css.marc_values(@one).should.equal [@one['245'].value.upcase]
|
163
|
+
end
|
164
|
+
|
165
|
+
|
166
|
+
it "uses a custom method with args but no map" do
|
167
|
+
css = MARCSpec::CustomSolrSpec.new(:solrField=>'solrField', :module=>A::B, :methodSymbol=>:titleUp, :methodArgs=>[['a', 'c']])
|
168
|
+
css.marc_values(@one).should.equal [@titleACValue.upcase]
|
169
|
+
end
|
170
|
+
|
171
|
+
it "works with a map" do
|
172
|
+
css = MARCSpec::CustomSolrSpec.new(:solrField=>'solrField', :map=>@map, :module=>A::B, :methodSymbol=>:titleUp, :methodArgs=>[['a', 'c']])
|
173
|
+
css.marc_values(@one).should.equal [@mapValue]
|
174
|
+
end
|
175
|
+
|
176
|
+
end
|
177
|
+
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bacon'
|
3
|
+
require 'marc4j4r'
|
4
|
+
require 'tempfile'
|
5
|
+
begin
|
6
|
+
require 'greeneggs'
|
7
|
+
rescue LoadError
|
8
|
+
end
|
9
|
+
|
10
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
11
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
12
|
+
require 'marcspec'
|
13
|
+
|
14
|
+
DIR = File.dirname(__FILE__)
|
15
|
+
|
16
|
+
Bacon.summary_on_exit
|
metadata
ADDED
@@ -0,0 +1,166 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: marcspec
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 21
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 2
|
9
|
+
- 1
|
10
|
+
version: 0.2.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- BillDueber
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-08-11 00:00:00 -04:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: bacon
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 3
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
version: "0"
|
33
|
+
type: :development
|
34
|
+
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: yard
|
37
|
+
prerelease: false
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
hash: 3
|
44
|
+
segments:
|
45
|
+
- 0
|
46
|
+
version: "0"
|
47
|
+
type: :development
|
48
|
+
version_requirements: *id002
|
49
|
+
- !ruby/object:Gem::Dependency
|
50
|
+
name: marc4j4r
|
51
|
+
prerelease: false
|
52
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
hash: 59
|
58
|
+
segments:
|
59
|
+
- 0
|
60
|
+
- 9
|
61
|
+
- 0
|
62
|
+
version: 0.9.0
|
63
|
+
type: :runtime
|
64
|
+
version_requirements: *id003
|
65
|
+
- !ruby/object:Gem::Dependency
|
66
|
+
name: jruby_streaming_update_solr_server
|
67
|
+
prerelease: false
|
68
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
69
|
+
none: false
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
hash: 23
|
74
|
+
segments:
|
75
|
+
- 0
|
76
|
+
- 2
|
77
|
+
- 0
|
78
|
+
version: 0.2.0
|
79
|
+
type: :runtime
|
80
|
+
version_requirements: *id004
|
81
|
+
description: Relies on marc4j4r, based on work in solrmarc
|
82
|
+
email: bill@dueber.com
|
83
|
+
executables: []
|
84
|
+
|
85
|
+
extensions: []
|
86
|
+
|
87
|
+
extra_rdoc_files:
|
88
|
+
- LICENSE
|
89
|
+
- README.rdoc
|
90
|
+
files:
|
91
|
+
- .document
|
92
|
+
- .gitignore
|
93
|
+
- LICENSE
|
94
|
+
- README.rdoc
|
95
|
+
- Rakefile
|
96
|
+
- VERSION
|
97
|
+
- lib/marcspec.rb
|
98
|
+
- lib/marcspec/customspec.rb
|
99
|
+
- lib/marcspec/kvmap.rb
|
100
|
+
- lib/marcspec/map.rb
|
101
|
+
- lib/marcspec/marcfieldspec.rb
|
102
|
+
- lib/marcspec/multivaluemap.rb
|
103
|
+
- lib/marcspec/solrfieldspec.rb
|
104
|
+
- lib/marcspec/specset.rb
|
105
|
+
- lib/orig.rb
|
106
|
+
- spec/data/batch.dat
|
107
|
+
- spec/data/one.dat
|
108
|
+
- spec/data/umich/translation_maps/area_map.properties
|
109
|
+
- spec/data/umich/translation_maps/availability_map_ht.properties
|
110
|
+
- spec/data/umich/translation_maps/availability_map_umich.properties
|
111
|
+
- spec/data/umich/translation_maps/callnumber_map.properties
|
112
|
+
- spec/data/umich/translation_maps/callnumber_subject_map.properties
|
113
|
+
- spec/data/umich/translation_maps/country_map.properties
|
114
|
+
- spec/data/umich/translation_maps/format_map.properties
|
115
|
+
- spec/data/umich/translation_maps/format_map_umich.properties
|
116
|
+
- spec/data/umich/translation_maps/ht_namespace_map.properties
|
117
|
+
- spec/data/umich/translation_maps/institution_map.properties
|
118
|
+
- spec/data/umich/translation_maps/language_map.properties
|
119
|
+
- spec/data/umich/translation_maps/library_map.properties
|
120
|
+
- spec/data/umich/translation_maps/location_map.properties
|
121
|
+
- spec/data/umich/umich_index.properties
|
122
|
+
- spec/maps_spec.rb
|
123
|
+
- spec/marcfieldspecs_spec.rb
|
124
|
+
- spec/marcspec_spec.rb
|
125
|
+
- spec/solrfieldspec_spec.rb
|
126
|
+
- spec/spec_helper.rb
|
127
|
+
has_rdoc: true
|
128
|
+
homepage: http://github.com/billdueber/marcspec
|
129
|
+
licenses: []
|
130
|
+
|
131
|
+
post_install_message:
|
132
|
+
rdoc_options:
|
133
|
+
- --charset=UTF-8
|
134
|
+
require_paths:
|
135
|
+
- lib
|
136
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
137
|
+
none: false
|
138
|
+
requirements:
|
139
|
+
- - ">="
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
hash: 3
|
142
|
+
segments:
|
143
|
+
- 0
|
144
|
+
version: "0"
|
145
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
146
|
+
none: false
|
147
|
+
requirements:
|
148
|
+
- - ">="
|
149
|
+
- !ruby/object:Gem::Version
|
150
|
+
hash: 3
|
151
|
+
segments:
|
152
|
+
- 0
|
153
|
+
version: "0"
|
154
|
+
requirements: []
|
155
|
+
|
156
|
+
rubyforge_project:
|
157
|
+
rubygems_version: 1.3.7
|
158
|
+
signing_key:
|
159
|
+
specification_version: 3
|
160
|
+
summary: Extract data from MARC records and send to Solr
|
161
|
+
test_files:
|
162
|
+
- spec/maps_spec.rb
|
163
|
+
- spec/marcfieldspecs_spec.rb
|
164
|
+
- spec/marcspec_spec.rb
|
165
|
+
- spec/solrfieldspec_spec.rb
|
166
|
+
- spec/spec_helper.rb
|