enhanced_marc 0.2.3 → 0.3.0

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.
@@ -1,22 +1,31 @@
1
+ # Methods for all/most record type
1
2
  module RecordType
2
-
3
+
3
4
  private
4
-
5
- def is_govdoc?(human_readable=false)
6
- govdoc_map={'a'=>'Autonomous or semiautonomous components', 'c'=>'Multilocal', 'f'=>'Federal',
7
- 'i'=>'International', 'l'=>'Local', 'm'=>'Multistate', 'o'=>'Undetermined', 's'=>'State', 'u'=>'Unknown', 'z'=>'Other'}
5
+
6
+ def govdoc?(human_readable = false)
7
+ govdoc_map = {
8
+ 'a' => 'Autonomous or semiautonomous components', 'c' => 'Multilocal',
9
+ 'f' => 'Federal', 'i' => 'International', 'l' => 'Local',
10
+ 'm' => 'Multistate', 'o' => 'Undetermined', 's' => 'State',
11
+ 'u' => 'Unknown', 'z' => 'Other'
12
+ }
8
13
  human_readable = govdoc_map if human_readable
9
- return self.field_parser({:match=>/^BKS$|^COM$|^MAP$|^SER$|^VIS$/, :start=>28,:end=>1}, {:match=>/[atmefsgkor]{1}/, :start=>11,:end=>1}, human_readable)
10
- end
11
-
14
+ field_parser(
15
+ { match: /^BKS$|^COM$|^MAP$|^SER$|^VIS$/, start: 28, end: 1 },
16
+ { match: /[atmefsgkor]{1}/, start: 11, end: 1 }, human_readable)
17
+ end
18
+
19
+ alias is_govdoc? govdoc?
20
+
12
21
  def nature_of_contents(human_readable=false)
13
22
  cont_map = {'a'=>'Abstracts','b'=>'Bibliography','c'=>'Catalog','d'=>'Dictionary',
14
23
  'e'=>'Encyclopedia', 'f'=>'Handbook', 'g'=>'Legal article', 'h'=>'Biography', 'i'=>'Index',
15
24
  'j'=>'Patent document', 'k'=>'Discography', 'l'=>'Legislation', 'm'=>'Thesis', 'n'=>'Literature survey',
16
- 'o'=>'Review', 'p'=>'Programmed text', 'q'=>'Filmography', 'r'=>'Directory', 's'=>'Statistics',
25
+ 'o'=>'Review', 'p'=>'Programmed text', 'q'=>'Filmography', 'r'=>'Directory', 's'=>'Statistics',
17
26
  't'=>'Technical report', 'u'=>'Standard/specification', 'v'=>'Legal case', 'w'=>'Law report', 'x'=>'Other report',
18
27
  'y'=>'Yearbook', 'z'=>'Treaty', '2'=>'Offprint', '5'=>'Calendar', '6'=>'Comic/Graphic Novel'}
19
-
28
+
20
29
  contents = []
21
30
  idx = nil
22
31
  if self.record_type == 'BKS'
@@ -27,7 +36,7 @@ module RecordType
27
36
  len = 3
28
37
  end
29
38
  if idx
30
- self['008'].value[idx,len].split(//).each { | char |
39
+ self['008'].value[idx,len].split(//).each { | char |
31
40
  next if char == " "
32
41
  if human_readable
33
42
  contents << cont_map[char] if cont_map[char]
@@ -44,9 +53,9 @@ module RecordType
44
53
  elsif fxd_fld.value[0,1].match('s')
45
54
  idx = 8
46
55
  len = 3
47
- end
48
- if idx
49
- fxd_fld.value[idx,len].split(//).each { | char |
56
+ end
57
+ if idx
58
+ fxd_fld.value[idx,len].split(//).each { | char |
50
59
  next if char == " "
51
60
  if human_readable
52
61
  contents << cont_map[char] if cont_map[char]
@@ -55,23 +64,24 @@ module RecordType
55
64
  end
56
65
  }
57
66
  end
58
- }
67
+ }
59
68
  return false if contents.empty?
60
- return contents
69
+ return contents
61
70
  end
62
-
63
71
 
64
- def is_conference?
65
- return true if self['008'].value[29,1] == '1' && @record_type.match(/^BKS$|^SER$/)
66
- return true if self['008'].value[30,2].match(/c/) && @record_type.match(/^SCO$|^REC$/)
67
- @fields.find_all {|f| ('006') === f.tag}.each { | fxd_fld |
68
- return true if fxd_fld.value[12,1] == '1' && fxd_fld.value[0,1].match(/[ats]{1}/)
69
72
 
70
- return true if fxd_fld.value[13,2].match(/c/) && fxd_fld.value[0,1].match(/[cdij]{1}/)
71
- }
72
- return false
73
+ def conference?
74
+ return true if self['008'].value[29, 1] == '1' && @record_type =~ /^BKS$|^SER$/
75
+ return true if self['008'].value[30, 2] =~ /c/ && @record_type =~ /^SCO$|^REC$/
76
+ @fields.each_by_tag('006') do |fxd_fld|
77
+ return true if fxd_fld.value[12, 1] == '1' && fxd_fld.value[0, 1] =~ /[ats]{1}/
78
+ return true if fxd_fld.value[13, 2] =~ /c/ && fxd_fld.value[0, 1] =~ /[cdij]{1}/
79
+ end
80
+ false
73
81
  end
74
-
82
+
83
+ alias is_conference? conference?
84
+
75
85
  def set_conference(value=false, field=nil)
76
86
  if field
77
87
  return Exception.new("Field is not an 006") unless field.tag == '006'
@@ -81,7 +91,7 @@ module RecordType
81
91
  else
82
92
  field.value[12] = '0'
83
93
  end
84
- else
94
+ else
85
95
  field = @fields['008']
86
96
  field = MARC::Controlfield.new('008') unless field
87
97
  if value
@@ -89,20 +99,20 @@ module RecordType
89
99
  else
90
100
  field[29] = '0'
91
101
  end
92
- end
93
-
94
- end
95
-
102
+ end
103
+
104
+ end
105
+
96
106
  def accompanying_matter(human_readable=false)
97
107
  accm_map = {'a'=>'Discography','b'=>'Bibliography','c'=>'Thematic index','d'=>'Libretto',
98
- 'e'=>'Composer biography', 'f'=>'Performer biography', 'g'=>'Technical/historical information on instruments',
108
+ 'e'=>'Composer biography', 'f'=>'Performer biography', 'g'=>'Technical/historical information on instruments',
99
109
  'h'=>'Technical information on music', 'i'=>'Historical information', 'j'=>'Historical information other than music',
100
- 'k'=>'Ethnological information', 'n'=>'Not applicable', 'r'=>'Instructional materials', 's'=>'Music',
110
+ 'k'=>'Ethnological information', 'n'=>'Not applicable', 'r'=>'Instructional materials', 's'=>'Music',
101
111
  'z'=>'Other accompanying matter'}
102
112
  matter = []
103
113
 
104
114
  if ['SCO', 'REC'].index(@record_type)
105
- self['008'].value[24,6].split(//).each { | char |
115
+ self['008'].value[24,6].split(//).each { | char |
106
116
  next if char == " "
107
117
  if human_readable
108
118
  matter << accm_map[char] if accm_map[char]
@@ -112,9 +122,9 @@ module RecordType
112
122
  }
113
123
  end
114
124
  @fields.find_all {|f| ('006') === f.tag}.each { | fxd_fld |
115
-
125
+
116
126
  if fxd_fld.value[0,1].match(/[cdij]{1}/)
117
- fxd_fld.value[7,6].split(//).each { | char |
127
+ fxd_fld.value[7,6].split(//).each { | char |
118
128
  next if char == " "
119
129
  if human_readable
120
130
  matter << accm_map[char]
@@ -123,19 +133,19 @@ module RecordType
123
133
  end
124
134
  }
125
135
  end
126
- }
136
+ }
127
137
  return false if matter.empty?
128
- return matter
129
- end
130
-
138
+ return matter
139
+ end
140
+
131
141
  def audience_level(human_readable=false)
132
142
  audn_map = {'a'=>'Preschool', 'b'=>'Children age 6-8', 'c'=>'Children age 9-13',
133
143
  'd'=>'Adolescent', 'e'=>'Adult', 'f'=>'Specialized', 'g'=>'General', 'j'=>'Juvenile'
134
144
  }
135
145
  human_readable = audn_map if human_readable
136
146
  return self.field_parser({:match=>/^BKS$|^VIS$|^MIX$|^MAP$|^SCO$|^REC$|^COM$/, :start=>22,:end=>1}, {:match=>/[atmefpcdijgkor]{1}/, :start=>5,:end=>1}, human_readable)
137
- end
138
-
147
+ end
148
+
139
149
  def form(human_readable=false)
140
150
  form_map = {'a'=>'Microfilm', 'b'=>'Microfiche', 'c'=>'Microopaque',
141
151
  'd'=>'Large print', 'f'=>'Braille', 'o'=>'Online', 'q'=>'Direct Electronic',
@@ -160,25 +170,25 @@ module RecordType
160
170
  idx = 6
161
171
  else
162
172
  idx = 12
163
- end
164
- next if fxd_fld.value[idx,1] == ' '
173
+ end
174
+ next if fxd_fld.value[idx,1] == ' '
165
175
  if human_readable
166
176
  return form_map[fxd_fld.value[idx,1]]
167
177
  else
168
178
  return fxd_fld.value[idx,1]
169
- end
170
- }
179
+ end
180
+ }
171
181
  return false
172
182
  end
173
-
183
+
174
184
  def has_index?
175
- return true if self['008'].value[31,1] == '1'
185
+ return true if self['008'].value[31,1] == '1'
176
186
  @fields.find_all {|f| ('006') === f.tag}.each { | fxd_fld |
177
187
  return true if fxd_fld.value[14,1] == '1'
178
- }
179
- return false
188
+ }
189
+ return false
180
190
  end
181
-
191
+
182
192
  def composition_form(human_readable=false)
183
193
  comp_map = {'an'=>'Anthem','bd'=>'Ballad','bt'=>'Ballet','bg'=>'Bluegrass music',
184
194
  'bl'=>'Blues','cn'=>'Canon or round','ct'=>'Catata','cz'=>'Canzona','cr'=>'Carol',
@@ -194,7 +204,7 @@ module RecordType
194
204
  'rg'=>'Ragtime music','rq'=>'Requiem','rp'=>'Rhapsody','ri'=>'Ricercars','rc'=>'Rock music',
195
205
  'rd'=>'Rondo','sn'=>'Sonata','sg'=>'Song','sd'=>'Square dance music','st'=>'Study/exercise',
196
206
  'su'=>'Suite','sp'=>'Symphonic poem','sy'=>'Symphony','tc'=>'Toccata','ts'=>'Trio-sonata',
197
- 'uu'=>'Unknown','vr'=>'Variation','wz'=>'Waltz','zz'=>'Other'
207
+ 'uu'=>'Unknown','vr'=>'Variation','wz'=>'Waltz','zz'=>'Other'
198
208
  }
199
209
  if @record_type.match(/^SCO$|^REC$/)
200
210
  unless self['008'].value[18,2] == ' '
@@ -214,54 +224,35 @@ module RecordType
214
224
  return fxd_fld.value[1,2]
215
225
  end
216
226
  end
217
- }
218
- return false
227
+ }
228
+ return false
219
229
  end
220
-
230
+
221
231
  def music_format(human_readable=false)
222
232
  fmus_map = {'a'=>'Full score','b'=>'Full score, miniature/study size','c'=>'Accompaniment reduced for keyboard',
223
233
  'd'=>'Voice score','e'=>'Condensed score','g'=>'Close score','m'=>'Multiple formats','n'=>'N/A',
224
234
  'u'=>'Unknown','z'=>'Other'}
225
235
  human_readable = fmus_map if human_readable
226
236
  return self.field_parser({:match=>/^SCO$|^REC$/, :start=>20,:end=>1}, {:match=>/[cdij]{1}/, :start=>3,:end=>1}, human_readable)
227
- # if self.record_type.match(/^SCO$|^REC$/)
228
- # unless self['008'].value[20,1] == ' '
229
- # if human_readable
230
- # return fmus_map[self['008'].value[20,1]]
231
- # else
232
- # return self['008'].value[20,1]
233
- # end
234
- # end
235
- # end
236
- ## @fields.find_all {|f| ('006') === f.tag}.each { | fxd_fld |
237
- # next unless fxd_fld.value[0,1].match(/[cdij]{1}/)
238
- # next if fxd_fld.value[3,1] == ' '
239
- # if human_readable
240
- # return fmus_map[fxd_fld.value[3,1]]
241
- # else
242
- # return fxd_fld.value[3,1]
243
- # end
244
- # }
245
- # return false
246
237
  end
247
-
238
+
248
239
  def has_index?
249
- return true if self['008'].value[31,1] == '1'
240
+ return true if self['008'].value[31,1] == '1'
250
241
  @fields.find_all {|f| ('006') === f.tag}.each { | fxd_fld |
251
242
  return true if fxd_fld.value[14,1] == '1'
252
- }
253
- return false
243
+ }
244
+ return false
254
245
  end
255
-
246
+
256
247
  def literary_text(human_readable=true)
257
248
  ltxt_map = {'a'=>'Autobiography', 'b'=>'Biography','c'=>'Conference proceeding','d'=>'Drama',
258
249
  'e'=>'Essay','f'=>'Fiction','g'=>'Reporting','h'=>'History','i'=>'Instruction','j'=>'Language instruction',
259
250
  'k'=>'Comedy','l'=>'Lecture/speech','m'=>'Memoir','n'=>'N/A','o'=>'Folktale','p'=>'Poetry','r'=>'Rehearsal',
260
251
  's'=>'Sounds','t'=>'Interview','z'=>'Other'}
261
252
  txts = []
262
-
253
+
263
254
  if ['SCO', 'REC'].index(@record_type)
264
- self['008'].value[30,2].split(//).each { | char |
255
+ self['008'].value[30,2].split(//).each { | char |
265
256
  next if char == " "
266
257
  if human_readable
267
258
  txts << ltxt_map[char]
@@ -271,9 +262,9 @@ module RecordType
271
262
  }
272
263
  end
273
264
  @fields.find_all {|f| ('006') === f.tag}.each { | fxd_fld |
274
-
265
+
275
266
  if fxd_fld.value[0,1].match(/[cdij]{1}/)
276
- fxd_fld.value[13,2].split(//).each { | char |
267
+ fxd_fld.value[13,2].split(//).each { | char |
277
268
  next if char == " "
278
269
  if human_readable
279
270
  txts << ltxt_map[char]
@@ -282,30 +273,30 @@ module RecordType
282
273
  end
283
274
  }
284
275
  end
285
- }
276
+ }
286
277
  return false if txts.empty?
287
- return txts
278
+ return txts
288
279
  end
289
280
  protected
290
- def field_parser(eight, six, human_readable_map=nil)
281
+ def field_parser(eight, six, human_readable_map = nil)
291
282
  if self.record_type.match(eight[:match])
292
- unless self['008'].value[eight[:start],eight[:end]] == ' '*eight[:end]
283
+ if self['008'].value[eight[:start], eight[:end]] !~ /[\s\\|]{#{eight[:end]}}/
293
284
  if human_readable_map
294
- return human_readable_map[self['008'].value[eight[:start],eight[:end]]]
285
+ return human_readable_map[self['008'].value[eight[:start], eight[:end]]]
295
286
  else
296
- return self['008'].value[eight[:start],eight[:end]]
287
+ return self['008'].value[eight[:start], eight[:end]]
297
288
  end
298
289
  end
299
290
  end
300
291
  @fields.find_all {|f| ('006') === f.tag}.each { | fxd_fld |
301
- next unless fxd_fld.value[0,1].match(six[:match])
302
- next if fxd_fld.value[six[:start],six[:end]] == ' '*six[:end]
292
+ next unless fxd_fld.value[0,1].match(six[:match])
293
+ next if fxd_fld.value[six[:start], six[:end]] =~ /[\s\\|]{#{six[:end]}}/
303
294
  if human_readable_map
304
295
  return human_readable_map[fxd_fld.value[six[:start],six[:end]]]
305
296
  else
306
- return fxd_fld.value[six[:start],six[:end]]
307
- end
308
- }
309
- return false
297
+ return fxd_fld.value[six[:start], six[:end]]
298
+ end
299
+ }
300
+ return false
310
301
  end
311
- end
302
+ end
@@ -1,4 +1,5 @@
1
1
  module ScoreType
2
2
  include RecordType
3
- public :accompanying_matter, :audience_level, :form, :composition_form, :music_format, :is_conference?
4
- end
3
+ public :accompanying_matter, :audience_level, :form, :composition_form,
4
+ :music_format, :is_conference?, :is_govdoc?, :govdoc?, :conference?
5
+ end
@@ -1,6 +1,6 @@
1
1
  module SerialType
2
2
  include RecordType
3
- public :is_govdoc?, :nature_of_contents, :is_conference?, :form
3
+ public :is_govdoc?, :nature_of_contents, :is_conference?, :form, :govdoc?, :conference?
4
4
  def alphabet(human_readable=false)
5
5
  alph_map = {'a'=>'Roman', 'b'=>'Extended Roman', 'c'=>'Cyrillic',
6
6
  'd'=>'Japanese', 'e'=>'Chinese', 'f'=>'Arabic', 'g'=>'Greek',
@@ -10,8 +10,8 @@ module SerialType
10
10
  human_readable = alph_map if human_readable
11
11
  return self.field_parser({:match=>'SER', :start=>33,:end=>1}, {:match=>'s', :start=>16,:end=>1}, human_readable)
12
12
  end
13
-
14
- def frequency(human_readable=false)
13
+
14
+ def frequency(human_readable=false)
15
15
  freq_map = {'a'=>'Annual','b'=>'Bimonthly','c'=>'Semiweekly','d'=>'Daily',
16
16
  'e'=>'Biweekly','f'=>'Semiannual','g'=>'Biennial','h'=>'Triennial','i'=>'3 times/week',
17
17
  'j'=>'3 times/month', 'k'=>'Continuously updated','m'=>'Monthly','q'=>'Quarterly',
@@ -19,52 +19,52 @@ module SerialType
19
19
  }
20
20
  human_readable = freq_map if human_readable
21
21
  resp = self.field_parser({:match=>'SER', :start=>18,:end=>1}, {:match=>'s', :start=>1,:end=>1}, human_readable)
22
- return resp if resp
22
+ return resp if resp
23
23
  if human_readable
24
24
  return 'No determinable frequency'
25
25
  else
26
26
  return false
27
27
  end
28
28
  end
29
-
29
+
30
30
  def regularity(human_readable=false)
31
31
  regl_map = {'n'=>'Normalized irregular','r'=>'Regular','u'=>'Unknown','x'=>'Completely irregular'}
32
32
  human_readable = regl_map if human_readable
33
33
  return self.field_parser({:match=>'SER', :start=>19,:end=>1}, {:match=>'s', :start=>2,:end=>1}, human_readable)
34
34
  end
35
-
35
+
36
36
  def serial_type(human_readable=false)
37
37
  srtp_map = {'d'=>'Database','l'=>'Loose-leaf','m'=>'Monographic series','n'=>'Newspaper','p'=>'Periodical','w'=>'Website'}
38
38
  human_readable = srtp_map if human_readable
39
39
  resp = self.field_parser({:match=>'SER', :start=>21,:end=>1}, {:match=>'s', :start=>4,:end=>1}, human_readable)
40
- return resp if resp
40
+ return resp if resp
41
41
  if human_readable
42
42
  return 'Other'
43
43
  else
44
44
  return false
45
- end
45
+ end
46
46
  end
47
-
47
+
48
48
  def original_form(human_readable=false)
49
49
  orig_map = {'a'=>'Microfilm','b'=>'Microfiche','c'=>'Microopaque','d'=>'Large print',
50
50
  'e'=>'Newspaper format','f'=>'Braille','s'=>'Electronic'}
51
51
  human_readable = orig_map if human_readable
52
52
  resp = self.field_parser({:match=>'SER', :start=>22,:end=>1}, {:match=>'s', :start=>5,:end=>1}, human_readable)
53
- return resp if resp
53
+ return resp if resp
54
54
 
55
55
  if human_readable
56
56
  return 'Other'
57
57
  else
58
58
  return false
59
- end
60
-
59
+ end
60
+
61
61
  end
62
-
62
+
63
63
  def nature_of_work(human_readable=false)
64
64
  entw_map = {'a'=>'Abstracts','b'=>'Bibliography','c'=>'Catalog','d'=>'Dictionary',
65
65
  'e'=>'Encyclopedia', 'f'=>'Handbook', 'g'=>'Legal article', 'h'=>'Biography', 'i'=>'Index',
66
66
  'j'=>'Patent document', 'k'=>'Discography', 'l'=>'Legislation', 'm'=>'Thesis', 'n'=>'Literature survey',
67
- 'o'=>'Review', 'p'=>'Programmed text', 'q'=>'Filmography', 'r'=>'Directory', 's'=>'Statistics',
67
+ 'o'=>'Review', 'p'=>'Programmed text', 'q'=>'Filmography', 'r'=>'Directory', 's'=>'Statistics',
68
68
  't'=>'Technical report', 'u'=>'Standard/specification', 'v'=>'Legal case', 'w'=>'Law report', 'x'=>'Other report',
69
69
  'z'=>'Treaty'}
70
70
 
@@ -75,13 +75,13 @@ module SerialType
75
75
  return 'Not specified'
76
76
  else
77
77
  return false
78
- end
79
-
78
+ end
79
+
80
80
  end
81
-
81
+
82
82
  def entry(human_readable=false)
83
83
  entry_map = {'0'=>'Successive','1'=>'Latest','2'=>'Integrated'}
84
84
  human_readable = entry_map if human_readable
85
- return self.field_parser({:match=>'SER', :start=>34,:end=>1}, {:match=>'s', :start=>17,:end=>1}, human_readable)
85
+ return self.field_parser({:match=>'SER', :start=>34,:end=>1}, {:match=>'s', :start=>17,:end=>1}, human_readable)
86
86
  end
87
- end
87
+ end
@@ -1,4 +1,5 @@
1
1
  module SoundType
2
2
  include RecordType
3
- public :accompanying_matter, :audience_level, :form, :composition_form, :music_format, :is_conference?
4
- end
3
+ public :accompanying_matter, :audience_level, :form, :composition_form,
4
+ :music_format, :is_conference?, :is_govdoc?, :govdoc?, :conference?
5
+ end