marc 0.4.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -1,4 +1,4 @@
1
- RUBY_MARC_VERSION = '0.4.0'
1
+ RUBY_MARC_VERSION = '0.4.1'
2
2
 
3
3
  require 'rubygems'
4
4
  require 'rake'
@@ -32,15 +32,15 @@
32
32
 
33
33
 
34
34
 
35
- require 'marc/constants'
36
- require 'marc/record'
37
- require 'marc/datafield'
38
- require 'marc/controlfield'
39
- require 'marc/subfield'
40
- require 'marc/reader'
41
- require 'marc/writer'
42
- require 'marc/exception'
43
- require 'marc/xmlwriter'
44
- require 'marc/xmlreader'
45
- require 'marc/dublincore'
46
- require 'marc/xml_parsers'
35
+ require File.dirname(__FILE__) + '/marc/constants'
36
+ require File.dirname(__FILE__) + '/marc/record'
37
+ require File.dirname(__FILE__) + '/marc/datafield'
38
+ require File.dirname(__FILE__) + '/marc/controlfield'
39
+ require File.dirname(__FILE__) + '/marc/subfield'
40
+ require File.dirname(__FILE__) + '/marc/reader'
41
+ require File.dirname(__FILE__) + '/marc/writer'
42
+ require File.dirname(__FILE__) + '/marc/exception'
43
+ require File.dirname(__FILE__) + '/marc/xmlwriter'
44
+ require File.dirname(__FILE__) + '/marc/xmlreader'
45
+ require File.dirname(__FILE__) + '/marc/dublincore'
46
+ require File.dirname(__FILE__) + '/marc/xml_parsers'
@@ -1,47 +1,4 @@
1
- require 'marc/subfield'
2
- require 'marc/record'
3
- require 'marc/controlfield'
4
-
5
1
  module MARC
6
-
7
- class SubfieldMap < Array
8
- attr_reader :codes
9
- def initialize
10
- @codes = HashWithChecksumAttribute.new
11
- end
12
-
13
- def in_sync?
14
- @codes.checksum == self.hash
15
- end
16
-
17
- def reindex
18
- @codes.clear
19
- self.each do |subfield|
20
- @codes[subfield.code] ||= []
21
- @codes[subfield.code] << self.index(subfield)
22
- end
23
- @codes.checksum = self.hash
24
- end
25
- def code_list
26
- reindex unless in_sync?
27
- @codes.keys
28
- end
29
-
30
- def each_by_code(codes)
31
- reindex unless in_sync?
32
- matched_codes = []
33
- [*codes].each do |code|
34
- next unless code && @codes[code]
35
- @codes[code].each do |idx|
36
- matched_codes << self[idx]
37
- yield self[idx]
38
- end
39
- end
40
- matched_codes
41
- end
42
-
43
- end
44
-
45
2
  # MARC records contain data fields, each of which has a tag,
46
3
  # indicators and subfields. Tags for data fields must are all
47
4
  # three-character tags that are not control fields (generally,
@@ -72,7 +29,7 @@ module MARC
72
29
  attr_accessor :indicator2
73
30
 
74
31
  # A list of MARC::Subfield objects
75
- #attr_accessor :subfields
32
+ attr_accessor :subfields
76
33
 
77
34
 
78
35
  # Create a new field with tag, indicators and subfields.
@@ -102,7 +59,8 @@ module MARC
102
59
  # screw us up later when we try to encode
103
60
  @indicator1 = i1 == nil ? ' ' : i1
104
61
  @indicator2 = i2 == nil ? ' ' : i2
105
- @subfields = SubfieldMap.new
62
+
63
+ @subfields = []
106
64
 
107
65
  # must use MARC::ControlField for tags < 010 or
108
66
  # those in MARC::ControlField#extra_control_fields
@@ -176,9 +134,9 @@ module MARC
176
134
  end
177
135
  end
178
136
 
179
- def each_by_code(filter)
180
- @subfields.each_by_code(filter)
181
- end
137
+ #def each_by_code(filter)
138
+ # @subfields.each_by_code(filter)
139
+ #end
182
140
 
183
141
  # You can lookup subfields with this shorthand. Note it
184
142
  # will return a string and not a MARC::Subfield object.
@@ -189,28 +147,12 @@ module MARC
189
147
  return subfield.value if subfield
190
148
  return
191
149
  end
192
-
193
- def subfields(filter=nil)
194
- return @subfields unless filter
195
- @subfields.reindex unless subfields.in_sync?
196
- subflds = []
197
- if filter.is_a?(String) && @subfields.codes[filter]
198
- @subfields.codes[filter].each do |idx|
199
- subflds << @subfields[idx]
200
- end
201
- elsif filter.is_a?(Array) || filter.is_a?(Range)
202
- filter.each do |code|
203
- next unless @subfields.codes[code]
204
- @subfields.codes[code].each do |idx|
205
- subflds << @subfields[idx]
206
- end
207
- end
208
- end
209
- subflds
210
- end
150
+
211
151
 
212
- def codes
213
- @subfields.code_list
152
+ def codes(dedupe=true)
153
+ codes = []
154
+ @subfields.each {|s| codes << s.code }
155
+ dedup ? codes.uniq : codes
214
156
  end
215
157
 
216
158
  # Two fields are equal if their tag, indicators and
@@ -1,43 +1,30 @@
1
- require 'marc/controlfield'
2
- require 'marc/datafield'
3
-
4
1
  module MARC
5
-
6
- # Simply what the class name says.
7
- # The checksum is used to see if the FieldMap's array has changed.
8
- class HashWithChecksumAttribute < Hash
9
- attr_accessor :checksum
10
- end
11
-
2
+
12
3
  # The FieldMap is an Array of DataFields and Controlfields.
13
- # It also contains a HashWithChecksumAttribute with a Hash-based
14
- # representation of the fields for faster lookups
4
+ # It also contains a Hash representation
5
+ # of the fields for faster lookups (under certain conditions)
15
6
  class FieldMap < Array
16
7
  attr_reader :tags
8
+ attr_accessor :clean
17
9
  def initialize
18
- @tags = HashWithChecksumAttribute.new
19
- end
20
-
21
- # Checks to see if the HashWithChecksumAttribute is in sync
22
- # with the Array of fields
23
- def in_sync?
24
- @tags.checksum == self.hash
10
+ @tags = {}
11
+ @clean = true
25
12
  end
26
13
 
27
14
  # Rebuild the HashWithChecksumAttribute with the current
28
15
  # values of the fields Array
29
16
  def reindex
30
- @tags.clear
31
- self.each do |field|
17
+ @tags = {}
18
+ self.each_with_index do |field, i|
32
19
  @tags[field.tag] ||= []
33
- @tags[field.tag] << self.index(field)
20
+ @tags[field.tag] << i
34
21
  end
35
- @tags.checksum = self.hash
22
+ @clean = true
36
23
  end
37
24
 
38
25
  # Returns an array of all of the tags that appear in the record (not in the order they appear, however).
39
26
  def tag_list
40
- reindex unless in_sync?
27
+ reindex unless @clean
41
28
  @tags.keys
42
29
  end
43
30
 
@@ -45,19 +32,12 @@ module MARC
45
32
  # The tags argument can be a string (e.g. '245'), an array (['100','700','800'])
46
33
  # or a range (('600'..'699')).
47
34
  def each_by_tag(tags)
48
- reindex unless in_sync?
49
- matched_tags = []
50
- [*tags].each do |tag|
51
- next unless tag && @tags[tag]
52
- @tags[tag].each do |idx|
53
- matched_tags[idx] = self[idx]
54
- end
55
- end
56
- matched_tags.compact!
57
- matched_tags.each do |tag|
35
+ reindex unless @clean
36
+ indices = @tags.values_at(*(@tags.keys & [*tags])).flatten.sort
37
+ return [] if indices.empty?
38
+ self.values_at(*indices).each do |tag|
58
39
  yield tag
59
40
  end
60
- matched_tags
61
41
  end
62
42
  end
63
43
 
@@ -100,12 +80,13 @@ module MARC
100
80
 
101
81
  def append(field)
102
82
  @fields.push(field)
83
+ @fields.clean = false
103
84
  end
104
85
 
105
86
  # alias to append
106
87
 
107
88
  def <<(field)
108
- append(field)
89
+ append(field)
109
90
  end
110
91
 
111
92
  # each() is here to support iterating and searching since MARC::Record
@@ -144,8 +125,11 @@ module MARC
144
125
  # a string, array or range of tags will return an array of fields
145
126
  # in the order they appear in the record.
146
127
  def fields(filter=nil)
147
- return @fields.to_a unless filter
148
- @fields.reindex unless @fields.in_sync?
128
+ unless filter
129
+ @fields.clean = false
130
+ return @fields
131
+ end
132
+ @fields.reindex unless @fields.clean
149
133
  flds = []
150
134
  if filter.is_a?(String) && @fields.tags[filter]
151
135
  @fields.tags[filter].each do |idx|
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: marc
3
3
  version: !ruby/object:Gem::Version
4
- hash: 15
4
+ hash: 13
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 4
9
- - 0
10
- version: 0.4.0
9
+ - 1
10
+ version: 0.4.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Kevin Clarke
@@ -19,7 +19,7 @@ autorequire: marc
19
19
  bindir: bin
20
20
  cert_chain: []
21
21
 
22
- date: 2010-09-21 00:00:00 -04:00
22
+ date: 2010-09-24 00:00:00 -04:00
23
23
  default_executable:
24
24
  dependencies: []
25
25
 
@@ -53,9 +53,7 @@ files:
53
53
  - test/one.dat
54
54
  - test/one.xml
55
55
  - test/random_tag_order.dat
56
- - test/random_tag_order.xml
57
56
  - test/random_tag_order2.dat
58
- - test/random_tag_order2.xml
59
57
  - test/tc_controlfield.rb
60
58
  - test/tc_datafield.rb
61
59
  - test/tc_dublincore.rb
@@ -1,72 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?><record xmlns="http://www.loc.gov/MARC21/slim" xmlns:cinclude="http://apache.org/cocoon/include/1.0" xmlns:zs="http://www.loc.gov/zing/srw/">
2
- <leader>01199njm a22002657a 4500</leader>
3
- <controlfield tag="001">5677437</controlfield>
4
- <controlfield tag="005">19930615144807.4</controlfield>
5
- <controlfield tag="007">sdubmmennmplu</controlfield>
6
- <controlfield tag="008">930430s1966 nyuuun eng </controlfield>
7
- <datafield tag="035" ind1=" " ind2=" ">
8
- <subfield code="9">(DLC) 93710188</subfield>
9
- </datafield>
10
- <datafield tag="906" ind1=" " ind2=" ">
11
- <subfield code="a">7</subfield>
12
- <subfield code="b">cbc</subfield>
13
- <subfield code="c">orignew</subfield>
14
- <subfield code="d">5</subfield>
15
- <subfield code="e">ncip</subfield>
16
- <subfield code="f">19</subfield>
17
- <subfield code="g">y-genmusic</subfield>
18
- </datafield>
19
- <datafield tag="010" ind1=" " ind2=" ">
20
- <subfield code="a"> 93710188 </subfield>
21
- </datafield>
22
- <datafield tag="028" ind1="0" ind2="0">
23
- <subfield code="a">C2L 41</subfield>
24
- <subfield code="b">Columbia</subfield>
25
- </datafield>
26
- <datafield tag="040" ind1=" " ind2=" ">
27
- <subfield code="a">DLC</subfield>
28
- <subfield code="c">DLC</subfield>
29
- </datafield>
30
- <datafield tag="050" ind1="0" ind2="0">
31
- <subfield code="a">Columbia C2L 41</subfield>
32
- </datafield>
33
- <datafield tag="245" ind1="0" ind2="0">
34
- <subfield code="a">Blonde on blonde</subfield>
35
- <subfield code="h">[sound recording].</subfield>
36
- </datafield>
37
- <datafield tag="260" ind1=" " ind2=" ">
38
- <subfield code="a">[New York, N.Y.] :</subfield>
39
- <subfield code="b">Columbia,</subfield>
40
- <subfield code="c">[1966?]</subfield>
41
- </datafield>
42
- <datafield tag="300" ind1=" " ind2=" ">
43
- <subfield code="a">2 sound discs :</subfield>
44
- <subfield code="b">analog, 33 1/3 rpm, mono. ;</subfield>
45
- <subfield code="c">12 in.</subfield>
46
- </datafield>
47
- <datafield tag="511" ind1="0" ind2=" ">
48
- <subfield code="a">Written and performed by Bob Dylan, vocals, harmonica ; with other musicians.</subfield>
49
- </datafield>
50
- <datafield tag="505" ind1="0" ind2=" ">
51
- <subfield code="a">Rainy day women #12 &amp; 35 -- Pledging my time -- Visions of Johanna -- One of us must know (Sooner or later) -- I want you -- Memphis blues again -- Leopard-skin pill-box hat -- Just like a woman -- Most likely you go your way and I'll go mine -- Temporary like Achilles -- Absolutely sweet Marie -- 4th time around -- Obviously 5 believers -- Sad eyed lady of the lowlands.</subfield>
52
- </datafield>
53
- <datafield tag="500" ind1=" " ind2=" ">
54
- <subfield code="a">Brief record.</subfield>
55
- </datafield>
56
- <datafield tag="650" ind1=" " ind2="0">
57
- <subfield code="a">Folk-rock music.</subfield>
58
- </datafield>
59
- <datafield tag="700" ind1="1" ind2=" ">
60
- <subfield code="a">Dylan, Bob,</subfield>
61
- <subfield code="d">1941-</subfield>
62
- <subfield code="4">prf</subfield>
63
- </datafield>
64
- <datafield tag="953" ind1=" " ind2=" ">
65
- <subfield code="a">TA28</subfield>
66
- </datafield>
67
- <datafield tag="991" ind1=" " ind2=" ">
68
- <subfield code="b">c-RecSound</subfield>
69
- <subfield code="h">Columbia C2L 41</subfield>
70
- <subfield code="w">MUSIC</subfield>
71
- </datafield>
72
- </record>
@@ -1,148 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?><record xmlns="http://www.loc.gov/MARC21/slim" xmlns:cinclude="http://apache.org/cocoon/include/1.0" xmlns:zs="http://www.loc.gov/zing/srw/">
2
- <leader>02500cjm a22004571a 4500</leader>
3
- <controlfield tag="001">13378768</controlfield>
4
- <controlfield tag="005">20070513203356.0</controlfield>
5
- <controlfield tag="007">sd fsngnnmmned</controlfield>
6
- <controlfield tag="008">031021p20032002ohubln ez eng d</controlfield>
7
- <datafield tag="035" ind1=" " ind2=" ">
8
- <subfield code="a">(DLC) 2003577486</subfield>
9
- </datafield>
10
- <datafield tag="040" ind1=" " ind2=" ">
11
- <subfield code="a">NTG</subfield>
12
- <subfield code="c">NTG</subfield>
13
- <subfield code="d">DLC</subfield>
14
- </datafield>
15
- <datafield tag="028" ind1="0" ind2="2">
16
- <subfield code="a">CD-83567</subfield>
17
- <subfield code="b">Telarc</subfield>
18
- </datafield>
19
- <datafield tag="041" ind1="0" ind2=" ">
20
- <subfield code="d">eng</subfield>
21
- <subfield code="g">eng</subfield>
22
- </datafield>
23
- <datafield tag="035" ind1=" " ind2=" ">
24
- <subfield code="a">(OCoLC)ocm52627255</subfield>
25
- </datafield>
26
- <datafield tag="024" ind1="1" ind2=" ">
27
- <subfield code="a">089408356728</subfield>
28
- </datafield>
29
- <datafield tag="028" ind1="0" ind2="2">
30
- <subfield code="a">CD-83567</subfield>
31
- <subfield code="b">Telarc Blues</subfield>
32
- </datafield>
33
- <datafield tag="010" ind1=" " ind2=" ">
34
- <subfield code="a"> 2003577486</subfield>
35
- </datafield>
36
- <datafield tag="042" ind1=" " ind2=" ">
37
- <subfield code="a">lcderive</subfield>
38
- </datafield>
39
- <datafield tag="050" ind1="0" ind2="0">
40
- <subfield code="a">SDA 80718</subfield>
41
- </datafield>
42
- <datafield tag="100" ind1="1" ind2=" ">
43
- <subfield code="a">Dylan, Bob,</subfield>
44
- <subfield code="d">1941-</subfield>
45
- </datafield>
46
- <datafield tag="245" ind1="1" ind2="0">
47
- <subfield code="a">Blues on Blonde on blonde</subfield>
48
- <subfield code="h">[sound recording] /</subfield>
49
- <subfield code="c">[all songs written by Bob Dylan].</subfield>
50
- </datafield>
51
- <datafield tag="246" ind1="3" ind2=" ">
52
- <subfield code="a">Blonde on blonde blues</subfield>
53
- </datafield>
54
- <datafield tag="260" ind1=" " ind2=" ">
55
- <subfield code="a">Cleveland, OH :</subfield>
56
- <subfield code="b">Telarc,</subfield>
57
- <subfield code="c">p2003.</subfield>
58
- </datafield>
59
- <datafield tag="300" ind1=" " ind2=" ">
60
- <subfield code="a">1 sound disc (67 min.) :</subfield>
61
- <subfield code="b">digital, stereo. ;</subfield>
62
- <subfield code="c">4 3/4 in.</subfield>
63
- </datafield>
64
- <datafield tag="306" ind1=" " ind2=" ">
65
- <subfield code="a">010717</subfield>
66
- </datafield>
67
- <datafield tag="440" ind1=" " ind2="0">
68
- <subfield code="a">Telarc blues</subfield>
69
- </datafield>
70
- <datafield tag="500" ind1=" " ind2=" ">
71
- <subfield code="a">"Contemporary blues" interpretations of previously released songs; written by Bob Dylan.</subfield>
72
- </datafield>
73
- <datafield tag="500" ind1=" " ind2=" ">
74
- <subfield code="a">Statement of responsibility from container insert.</subfield>
75
- </datafield>
76
- <datafield tag="511" ind1="0" ind2=" ">
77
- <subfield code="a">Various performers.</subfield>
78
- </datafield>
79
- <datafield tag="518" ind1=" " ind2=" ">
80
- <subfield code="a">Recorded July 2002 at the Studio, Portland, Maine.</subfield>
81
- </datafield>
82
- <datafield tag="500" ind1=" " ind2=" ">
83
- <subfield code="a">"Nearly thirty years after the debut of Bob Dylan's 'Blonde on blonde', Telarc assembles some of the finest artists on the contemporary blues scene to salute the monumental blues/folk/rock recording"--Container exterior sheet.</subfield>
84
- </datafield>
85
- <datafield tag="500" ind1=" " ind2=" ">
86
- <subfield code="a">"Fully 27 years after the debut of 'Blonde on blonde', Telarc gathered an assembly of contemporary blues artists to pay tribute to Dylan's masterpiece from his controversial electric period"--All Music Guide.</subfield>
87
- </datafield>
88
- <datafield tag="500" ind1=" " ind2=" ">
89
- <subfield code="a">Compact disc.</subfield>
90
- </datafield>
91
- <datafield tag="500" ind1=" " ind2=" ">
92
- <subfield code="a">Composer and program notes in container.</subfield>
93
- </datafield>
94
- <datafield tag="505" ind1="0" ind2="0">
95
- <subfield code="t">Rainy day women # 12 &amp; 35</subfield>
96
- <subfield code="r">(Brian Stoltz) --</subfield>
97
- <subfield code="t">Most likely you go your way and I'll go mine</subfield>
98
- <subfield code="r">(Sue Foley) --</subfield>
99
- <subfield code="t">Leopard-skin pill-box hat</subfield>
100
- <subfield code="r">(Walter Trout) --</subfield>
101
- <subfield code="t">Visions of Johanna</subfield>
102
- <subfield code="r">(Anders Osborne) --</subfield>
103
- <subfield code="t">Pledging my time</subfield>
104
- <subfield code="r">(Duke Robillard) --</subfield>
105
- <subfield code="t">Just like a woman</subfield>
106
- <subfield code="r">(Eric Bibb) --</subfield>
107
- <subfield code="t">Stuck inside of Mobile with the Memphis blues again</subfield>
108
- <subfield code="r">(Joe Louis Walker) --</subfield>
109
- <subfield code="t">Obviously 5 believers</subfield>
110
- <subfield code="r">(Sean Costello) --</subfield>
111
- <subfield code="t">One of us must know (sooner or later)</subfield>
112
- <subfield code="r">(Clarence Bucaro) --</subfield>
113
- <subfield code="t">Temporary like Achilles</subfield>
114
- <subfield code="r">(Deborah Coleman) --</subfield>
115
- <subfield code="t">I want you</subfield>
116
- <subfield code="r">(Cyril Neville) --</subfield>
117
- <subfield code="t">Absolutely sweet Marie</subfield>
118
- <subfield code="r">(C.J. Chenier).</subfield>
119
- </datafield>
120
- <datafield tag="650" ind1=" " ind2="0">
121
- <subfield code="a">Blues (Music)</subfield>
122
- </datafield>
123
- <datafield tag="906" ind1=" " ind2=" ">
124
- <subfield code="a">7</subfield>
125
- <subfield code="b">cbc</subfield>
126
- <subfield code="c">copycat</subfield>
127
- <subfield code="d">3</subfield>
128
- <subfield code="e">ncip</subfield>
129
- <subfield code="f">20</subfield>
130
- <subfield code="g">y-genmusic</subfield>
131
- </datafield>
132
- <datafield tag="925" ind1="0" ind2=" ">
133
- <subfield code="a">acquire</subfield>
134
- <subfield code="b">2 copies</subfield>
135
- <subfield code="x">policy default</subfield>
136
- </datafield>
137
- <datafield tag="952" ind1=" " ind2=" ">
138
- <subfield code="a">muzerec</subfield>
139
- </datafield>
140
- <datafield tag="955" ind1=" " ind2=" ">
141
- <subfield code="a">vn22 2003-10-28 to MBRS/RS</subfield>
142
- <subfield code="e">vn17 2004-02-25 copy 2 to MBRS/RS</subfield>
143
- </datafield>
144
- <datafield tag="985" ind1=" " ind2=" ">
145
- <subfield code="c">OCLC</subfield>
146
- <subfield code="e">srreplace 2004-01</subfield>
147
- </datafield>
148
- </record>