marcspec 0.7.3 → 0.8.1

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 CHANGED
@@ -1,3 +1,9 @@
1
+ 0.8.1
2
+ * Added some specs, squashed some bugs. In particular, make sure the Range passed to a ControlField
3
+ makes sense (x..y, where x<=y and x > 0)
4
+ 0.8.0
5
+ * Changed the syntax for a variable field from ['245', '*', '*', 'ab'] to just ['245', 'ab']. We'll worry
6
+ about indicators when that bridge gets crossed.
1
7
  0.7.3
2
8
  * Squashed a bug where I forgot to deal with escaping in java .properties files. Now I'm just using
3
9
  a real Java Properties object so I don't have to worry about it.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.7.3
1
+ 0.8.1
@@ -21,7 +21,7 @@ module MARCSpec
21
21
 
22
22
  def initialize (tag, range=nil)
23
23
  unless MARC4J4R::ControlField.control_tag? tag
24
- raise ArgumentError "Tag must be a control tag"
24
+ raise ArgumentError, "Tag must be a control tag"
25
25
  end
26
26
  @tag = tag
27
27
  self.range = range
@@ -53,7 +53,11 @@ module MARCSpec
53
53
  @range = range..range
54
54
 
55
55
  elsif range.is_a? Range
56
- @range = range
56
+ if range.begin < 1 or range.begin > range.end
57
+ raise ArgumentError "Range must be one-based, with the start before the end, not #{range}"
58
+ else
59
+ @range = range
60
+ end
57
61
  else
58
62
  raise ArgumentError, "Range must be nil, an integer offset (1-based), or a Range, not #{range.inspect}"
59
63
  end
@@ -54,7 +54,7 @@ module MARCSpec
54
54
  @functionSymbol = opts[:functionSymbol]
55
55
 
56
56
  unless @solrField and @module and @functionSymbol
57
- raise ArgumentError, "Custom solr spec must have a field name in :solrField, module in :module, and the method name as a symbol in :functionSymbol"
57
+ raise ArgumentError, "Custom solr spec must have a field name in :solrField, module in :module, and the function name as a symbol in :functionSymbol"
58
58
  end
59
59
 
60
60
 
@@ -15,7 +15,7 @@ module MARCSpec
15
15
 
16
16
  def initialize (tag, range=nil)
17
17
  unless tag == 'LDR'
18
- raise ArgumentError "Tag must be 'LDR' for a LeaderSpec"
18
+ raise ArgumentError, "Tag must be 'LDR' for a LeaderSpec"
19
19
  end
20
20
  @tag = 'LDR'
21
21
  self.range = range
@@ -1,4 +1,6 @@
1
1
  require 'stringio'
2
+ require 'marc4j4r/controlfield'
3
+
2
4
  module MARCSpec
3
5
  class SolrFieldSpec
4
6
  attr_accessor :solrField, :first, :map, :noMapKeyDefault, :marcfieldspecs, :default, :arity
@@ -77,10 +79,10 @@ module MARCSpec
77
79
  def self.fromHash h
78
80
  sfs = self.new(h)
79
81
  h[:specs].each do |s|
80
- if s.size < 3
82
+ if MARC4J4R::ControlField.control_tag? s[0]
81
83
  sfs << MARCSpec::ControlFieldSpec.new(*s)
82
84
  else
83
- sfs << MARCSpec::VariableFieldSpec.new(s[0], s[3], s[4])
85
+ sfs << MARCSpec::VariableFieldSpec.new(s[0], s[1], s[2])
84
86
  end
85
87
  end
86
88
  return sfs
@@ -1,5 +1,5 @@
1
1
  require 'jruby_streaming_update_solr_server'
2
-
2
+ require 'marc4j4r'
3
3
 
4
4
 
5
5
 
@@ -15,7 +15,7 @@ module MARCSpec
15
15
 
16
16
  class VariableFieldSpec
17
17
 
18
- attr_accessor :tag, :codes, :joiner
18
+ attr_accessor :tag, :codes, :joiner, :ind1, :ind2
19
19
 
20
20
  def initialize tag, codes=nil, joiner=' '
21
21
  @tag = tag
@@ -63,16 +63,16 @@ module MARCSpec
63
63
  def asPPString
64
64
  s = StringIO.new
65
65
  if @joiner and @joiner != ' '
66
- PP.pp([@tag, '*', '*', @codes.join(''), @joiner], s)
66
+ PP.pp([@tag, @codes.join(''), @joiner], s)
67
67
  else
68
- PP.pp([@tag, '*', '*', @codes.join('')], s)
68
+ PP.pp([@tag, @codes.join('')], s)
69
69
  end
70
70
  return s.string
71
71
  end
72
72
 
73
73
  def self.fromPPString str
74
74
  a = eval(str)
75
- return self.new(a[0], a[3], a[4])
75
+ return self.new(a[0], a[1], a[2])
76
76
  end
77
77
 
78
78
  end
@@ -18,6 +18,94 @@ require 'spec_helper'
18
18
  # 852 $a American Folklife Center, Library of Congress
19
19
  # 852 $a DLC
20
20
 
21
+ describe "ControlFieldSpec" do
22
+
23
+ before do
24
+ @one = MARC4J4R::Reader.new("#{DIR}/data/one.dat").first
25
+ # @batch = MARC4J4R::Reader.new("#{DIR}/batch.dat").collect
26
+ end
27
+
28
+ # afc99990058366 # data
29
+ # 01234567890123 # index
30
+ it "gets a single full value" do
31
+ cfs = MARCSpec::ControlFieldSpec.new('001')
32
+ cfs.marc_values(@one).should.equal ["afc99990058366"]
33
+ end
34
+
35
+ it "gets a single character" do
36
+ cfs = MARCSpec::ControlFieldSpec.new('001', 10 )
37
+ cfs.marc_values(@one).should.equal ['8']
38
+ end
39
+
40
+ it "gets a range of characters" do
41
+ cfs = MARCSpec::ControlFieldSpec.new('001', 6..10 )
42
+ cfs.marc_values(@one).should.equal ['90058']
43
+ end
44
+
45
+ it "should round trip" do
46
+ cfs = MARCSpec::ControlFieldSpec.new('001', 6..10 )
47
+ cfs2 = MARCSpec::ControlFieldSpec.fromPPString(cfs.asPPString)
48
+ cfs.should.equal cfs2
49
+ end
50
+
51
+ it "throws an error if you try to use a datafield tag" do
52
+ lambda{
53
+ cfs = MARCSpec::ControlFieldSpec.new('010', 6..10 )
54
+ }.should.raise ArgumentError
55
+ end
56
+
57
+ it "accepts various forms for the range" do
58
+ cfs1 = MARCSpec::ControlFieldSpec.new('001')
59
+ cfs2 = MARCSpec::ControlFieldSpec.new('001')
60
+ cfs3 = MARCSpec::ControlFieldSpec.new('001')
61
+
62
+ # Range 4-7 is 9999
63
+ cfs1.range = 4
64
+ cfs2.range = 4..4
65
+ cfs1.marc_values(@one).should.equal ['9']
66
+ cfs2.marc_values(@one).should.equal ['9']
67
+ end
68
+
69
+ it "rejects bad ranges" do
70
+ lambda{
71
+ cfs = MARCSpec::ControlFieldSpec.new('010', -1)
72
+ }.should.raise ArgumentError
73
+
74
+ lambda{
75
+ cfs = MARCSpec::ControlFieldSpec.new('010', -1..3)
76
+ }.should.raise ArgumentError
77
+
78
+ lambda{
79
+ cfs = MARCSpec::ControlFieldSpec.new('010', [1,2,3])
80
+ }.should.raise ArgumentError
81
+ end
82
+ end
83
+
84
+
85
+ describe "LeaderSpec" do
86
+ before do
87
+ @one = MARC4J4R::Reader.new("#{DIR}/data/one.dat").first
88
+ end
89
+
90
+ it "must use LDR as the tag" do
91
+ lambda{
92
+ cfs = MARCSpec::LeaderSpec.new('008')
93
+ }.should.raise ArgumentError
94
+ end
95
+
96
+ it "Works with full leader" do
97
+ cfs = MARCSpec::LeaderSpec.new('LDR')
98
+ cfs.marc_values(@one).should.equal @one.leader
99
+ end
100
+
101
+ it "Works with substring of leader" do
102
+ cfs = MARCSpec::LeaderSpec.new('LDR', 3..5)
103
+ cfs.marc_values(@one).should.equal @one.leader[3..5]
104
+ end
105
+ end
106
+
107
+
108
+
21
109
  describe "VariableFieldSpec" do
22
110
  before do
23
111
  @one = MARC4J4R::Reader.new("#{DIR}/data/one.dat").first
@@ -164,6 +164,18 @@ describe "CustomSolrSpec" do
164
164
  @map = MARCSpec::KVMap.new('nameOfTheMap', {@titleACValue.upcase => @mapValue, @default=>@mapValueForDefault})
165
165
  end
166
166
 
167
+ it "requires solrfield, module, and function" do
168
+ lambda{
169
+ css = MARCSpec::CustomSolrSpec.new(:solrField=>'solrField')
170
+ }.should.raise ArgumentError
171
+ lambda{
172
+ css = MARCSpec::CustomSolrSpec.new(:solrField=>'solrField', :module=>A::B)
173
+ }.should.raise ArgumentError
174
+ lambda{
175
+ css = MARCSpec::CustomSolrSpec.new(:module=>A::B, :functionSymbol=>:titleUp)
176
+ }.should.raise ArgumentError
177
+ end
178
+
167
179
  it "works with no args or map" do
168
180
  css = MARCSpec::CustomSolrSpec.new(:solrField=>'solrField', :module=>A::B, :functionSymbol=>:titleUp)
169
181
  css.marc_values(@one).should.equal [@one['245'].value.upcase]
@@ -191,6 +203,14 @@ describe "CustomSolrSpec" do
191
203
  css.marc_values(@one).should.equal ['two', 'one']
192
204
  end
193
205
 
206
+ it "disallows multispecs with maps or default values" do
207
+ lambda{
208
+ css = MARCSpec::CustomSolrSpec.new(:solrField=>['s1', 's2'], :module=>A::B, :functionSymbol=>:titleUp, :map=>@map)
209
+ }.should.raise ArgumentError
210
+ lambda{
211
+ css = MARCSpec::CustomSolrSpec.new(:solrField=>['s1', 's2'], :module=>A::B, :functionSymbol=>:titleUp, :default=>"bill")
212
+ }.should.raise ArgumentError
213
+ end
194
214
 
195
215
  end
196
216
 
data/spec/specset_spec.rb CHANGED
@@ -41,15 +41,15 @@ describe "SpecSet Basics" do
41
41
  {
42
42
  :solrField=> "places",
43
43
  :specs => [
44
- ["260", "*", "*", "a"],
45
- ["651", "*", "*", "a"],
46
- ["651", "*", "*", "z"],
44
+ ["260", "a"],
45
+ ["651", "a"],
46
+ ["651", "z"],
47
47
  ]
48
48
  },
49
- {:solrField=>'title', :specs=>[['245', '*', '*']]},
49
+ {:solrField=>'title', :specs=>[['245']]},
50
50
  {
51
51
  :solrField => 'titleA',
52
- :specs => [['245', '*', '*', 'a']]
52
+ :specs => [['245', 'a']]
53
53
  }
54
54
  ]
55
55
  end
@@ -74,7 +74,7 @@ describe "SpecSet Basics" do
74
74
  end
75
75
 
76
76
  it "should allow repeated solrFields" do
77
- @speclist << {:solrField=>'titleA', :specs=>[['260', '*', '*', 'c']]} # '1939.'
77
+ @speclist << {:solrField=>'titleA', :specs=>[['260', 'c']]} # '1939.'
78
78
  expected = @titleA
79
79
  expected << '1939.'
80
80
  ss = MARCSpec::SpecSet.new
@@ -95,8 +95,6 @@ describe "SpecSet Basics" do
95
95
  h['two'].should.equal [2]
96
96
  h['letters'].should.equal ['a', 'b']
97
97
  end
98
-
99
-
100
98
  end
101
99
 
102
100
 
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: 5
4
+ hash: 61
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 7
9
- - 3
10
- version: 0.7.3
8
+ - 8
9
+ - 1
10
+ version: 0.8.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - BillDueber
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-08-25 00:00:00 -04:00
18
+ date: 2010-09-04 00:00:00 -04:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -123,12 +123,10 @@ files:
123
123
  - spec/data/umich/translation_maps/location_map.properties
124
124
  - spec/data/umich/umich_index.properties
125
125
  - spec/maps_spec.rb
126
+ - spec/marcfieldspecs_spec.rb
126
127
  - spec/solrfieldspec_spec.rb
127
128
  - spec/spec_helper.rb
128
129
  - spec/specset_spec.rb
129
- - spec/controlfieldspec_spec.rb
130
- - spec/leaderspec_spec.rb
131
- - spec/variablefieldspec_spec.rb
132
130
  has_rdoc: true
133
131
  homepage: http://github.com/billdueber/marcspec
134
132
  licenses: []
@@ -164,10 +162,8 @@ signing_key:
164
162
  specification_version: 3
165
163
  summary: Extract data from MARC records and send to Solr
166
164
  test_files:
167
- - spec/controlfieldspec_spec.rb
168
- - spec/leaderspec_spec.rb
169
165
  - spec/maps_spec.rb
166
+ - spec/marcfieldspecs_spec.rb
170
167
  - spec/solrfieldspec_spec.rb
171
168
  - spec/spec_helper.rb
172
169
  - spec/specset_spec.rb
173
- - spec/variablefieldspec_spec.rb
@@ -1,52 +0,0 @@
1
- require 'spec_helper'
2
-
3
- # LEADER 00734njm a2200217uu 4500
4
- # 001 afc99990058366
5
- # 003 DLC
6
- # 005 20071104155141.9
7
- # 007 sd ummunniauub
8
- # 008 071103s1939 xxufmnne||||||||| u eng||
9
- # 010 $a afc99990058366
10
- # 040 $a DLC $c DLC
11
- # 245 04 $a The Texas ranger $h [sound recording] / $c Sung by Beale D. Taylor.
12
- # 260 $a Medina, Texas, $c 1939.
13
- # 300 $a 1 sound disc : $b analog, 33 1/3 rpm, mono. ; $c 12 in.
14
- # 651 0 $a Medina $z Texas $z United States of America.
15
- # 700 1 $a Lomax, John Avery, 1867-1948 $e Recording engineer.
16
- # 700 1 $a Lomax, Ruby T. (Ruby Terrill) $e Recording engineer.
17
- # 700 1 $a Taylor, Beale D. $e Singer.
18
- # 852 $a American Folklife Center, Library of Congress
19
- # 852 $a DLC
20
-
21
- describe "ControlFieldSpec" do
22
-
23
- before do
24
- @one = MARC4J4R::Reader.new("#{DIR}/data/one.dat").first
25
- # @batch = MARC4J4R::Reader.new("#{DIR}/batch.dat").collect
26
- end
27
-
28
- # afc99990058366 # data
29
- # 01234567890123 # index
30
- it "gets a single full value" do
31
- cfs = MARCSpec::ControlFieldSpec.new('001')
32
- cfs.marc_values(@one).should.equal ["afc99990058366"]
33
- end
34
-
35
- it "gets a single character" do
36
- cfs = MARCSpec::ControlFieldSpec.new('001', 10 )
37
- cfs.marc_values(@one).should.equal ['8']
38
- end
39
-
40
- it "gets a range of characters" do
41
- cfs = MARCSpec::ControlFieldSpec.new('001', 6..10 )
42
- cfs.marc_values(@one).should.equal ['90058']
43
- end
44
-
45
- it "should round trip" do
46
- cfs = MARCSpec::ControlFieldSpec.new('001', 6..10 )
47
- cfs2 = MARCSpec::ControlFieldSpec.fromPPString(cfs.asPPString)
48
- cfs.should.equal cfs2
49
- end
50
- end
51
-
52
-
@@ -1,35 +0,0 @@
1
- require 'spec_helper'
2
-
3
- # LEADER 00734njm a2200217uu 4500
4
- # 001 afc99990058366
5
- # 003 DLC
6
- # 005 20071104155141.9
7
- # 007 sd ummunniauub
8
- # 008 071103s1939 xxufmnne||||||||| u eng||
9
- # 010 $a afc99990058366
10
- # 040 $a DLC $c DLC
11
- # 245 04 $a The Texas ranger $h [sound recording] / $c Sung by Beale D. Taylor.
12
- # 260 $a Medina, Texas, $c 1939.
13
- # 300 $a 1 sound disc : $b analog, 33 1/3 rpm, mono. ; $c 12 in.
14
- # 651 0 $a Medina $z Texas $z United States of America.
15
- # 700 1 $a Lomax, John Avery, 1867-1948 $e Recording engineer.
16
- # 700 1 $a Lomax, Ruby T. (Ruby Terrill) $e Recording engineer.
17
- # 700 1 $a Taylor, Beale D. $e Singer.
18
- # 852 $a American Folklife Center, Library of Congress
19
- # 852 $a DLC
20
-
21
- describe "LeaderSpec" do
22
- before do
23
- @one = MARC4J4R::Reader.new("#{DIR}/data/one.dat").first
24
- end
25
-
26
- it "Works with full leader" do
27
- cfs = MARCSpec::LeaderSpec.new('LDR')
28
- cfs.marc_values(@one).should.equal @one.leader
29
- end
30
-
31
- it "Works with substring of leader" do
32
- cfs = MARCSpec::LeaderSpec.new('LDR', 3..5)
33
- cfs.marc_values(@one).should.equal @one.leader[3..5]
34
- end
35
- end