mods 0.0.16 → 0.0.17

Sign up to get free protection for your applications and to get access to all the features.
@@ -78,19 +78,19 @@ module Mods
78
78
  @mods_ng_xml.title_info.sort_title.find { |n| !n.nil? }
79
79
  end
80
80
 
81
- # use the displayForm of a personal name if present
82
- # if no displayForm, try to make a string from family name and given name "family_name, given_name"
83
- # otherwise, return all nameParts concatenated together
84
- # @return Array of Strings, each containing the above described string
81
+ # @return Array of Strings, each containing the computed display value of a personal name
82
+ # (see nom_terminology for algorithm)
85
83
  def personal_names
86
84
  @mods_ng_xml.personal_name.map { |n|
87
- if n.displayForm.size > 0
88
- n.displayForm.text
89
- elsif n.family_name.size > 0
90
- n.given_name.size > 0 ? n.family_name.text + ', ' + n.given_name.text : n.family_name.text
91
- else
92
- n.namePart.text
93
- end
85
+ n.display_value
86
+ }
87
+ end
88
+
89
+ # @return Array of Strings, each containing the computed display value of a personal name
90
+ # (see nom_terminology for algorithm)
91
+ def personal_names_w_dates
92
+ @mods_ng_xml.personal_name.map { |n|
93
+ n.display_value_w_date
94
94
  }
95
95
  end
96
96
 
@@ -99,11 +99,7 @@ module Mods
99
99
  # @return Array of Strings, each containing the above described string
100
100
  def corporate_names
101
101
  @mods_ng_xml.corporate_name.map { |n|
102
- if n.displayForm.size > 0
103
- n.displayForm.text
104
- else
105
- n.namePart.text
106
- end
102
+ n.display_value
107
103
  }
108
104
  end
109
105
 
@@ -1,4 +1,4 @@
1
1
  module Mods
2
2
  # this is the Ruby Gem version
3
- VERSION = "0.0.16"
3
+ VERSION = "0.0.17"
4
4
  end
@@ -74,7 +74,7 @@ describe "Mods <name> Element" do
74
74
  @mods_rec.personal_name.role.roleTerm.authority.should == ["marcrelator"]
75
75
  end
76
76
  end # roles
77
- end # WITH namespaces
77
+ end # WITH namespaces (personal name)
78
78
 
79
79
  context "WITHOUT namespaces" do
80
80
  it "should recognize child elements" do
@@ -215,7 +215,7 @@ describe "Mods <name> Element" do
215
215
  end
216
216
  end
217
217
 
218
- end # context WITH namespaces
218
+ end # context WITH namespaces (plain_name)
219
219
 
220
220
  context "WITHOUT namespaces" do
221
221
  it "should recognize child elements" do
@@ -266,6 +266,260 @@ describe "Mods <name> Element" do
266
266
  MARC_RELATOR['drt'].should == "Director"
267
267
  end
268
268
 
269
+ context "display_value and display_value_w_date" do
270
+ before(:all) do
271
+ @disp_form = 'q'
272
+ @pname1_xml = "<mods #{@ns_decl}><name type='personal'>
273
+ <namePart type='given'>John</namePart>
274
+ <namePart type='family'>Huston</namePart>
275
+ <displayForm>#{@disp_form}</displayForm>
276
+ </name></mods>"
277
+ @cname_xml = "<mods #{@ns_decl}><name type='corporate'>
278
+ <namePart>Watchful Eye</namePart>
279
+ </name></mods>"
280
+ @affl = 'affliation'
281
+ @desc = 'description'
282
+ @role = 'role'
283
+ @name_xml = "<mods #{@ns_decl}><name>
284
+ <namePart>Exciting Prints</namePart>
285
+ <affiliation>#{@affl}</affiliation>
286
+ <description>#{@desc}</description>
287
+ <role><roleTerm type='text'>#{@role}</roleTerm></role>
288
+ </name></mods>"
289
+ @namepart_xml = "<mods #{@ns_decl}><name>
290
+ <namePart>Suzy</namePart>
291
+ <namePart type='date'>1920-</namePart>
292
+ </name></mods>"
293
+ end
294
+ context "WITH namespaces" do
295
+ before(:all) do
296
+ @mods_pname1 = Mods::Record.new.from_str(@pname1_xml)
297
+ @mods_cname = Mods::Record.new.from_str(@cname_xml)
298
+ @mods_name = Mods::Record.new.from_str(@name_xml)
299
+ @mods_namepart_date = Mods::Record.new.from_str(@namepart_xml)
300
+ end
301
+ it "should be a string value for each name, not an Array" do
302
+ @mods_name.plain_name.first.display_value.should be_an_instance_of(String)
303
+ @mods_name.plain_name.first.display_value_w_date.should be_an_instance_of(String)
304
+ end
305
+ it "should return nil when there is no display_value" do
306
+ x = "<mods #{@ns_decl}><name>
307
+ <namePart></namePart>
308
+ </name></mods>"
309
+ r = Mods::Record.new.from_str(x)
310
+ r.plain_name.first.display_value.should == nil
311
+ end
312
+ it "should be applicable to all name term flavors (plain_name, personal_name, corporate_name ...)" do
313
+ @mods_name.plain_name.first.display_value.should_not == nil
314
+ @mods_name.plain_name.first.display_value_w_date.should_not == nil
315
+ @mods_pname1.personal_name.first.display_value.should_not == nil
316
+ @mods_pname1.personal_name.first.display_value_w_date.should_not == nil
317
+ @mods_cname.corporate_name.first.display_value.should_not == nil
318
+ @mods_cname.corporate_name.first.display_value_w_date.should_not == nil
319
+ end
320
+ it "should not include <affiliation> text" do
321
+ @mods_name.plain_name.first.display_value.should_not =~ Regexp.new(@affl)
322
+ end
323
+ it "should not include <description> text" do
324
+ @mods_name.plain_name.first.display_value.should_not =~ Regexp.new(@desc)
325
+ end
326
+ it "should not include <role> info" do
327
+ @mods_name.plain_name.first.display_value.should_not =~ Regexp.new(@role)
328
+ end
329
+ it "should be the value of the <displayForm> subelement if it exists" do
330
+ @mods_pname1.plain_name.first.display_value.should == @disp_form
331
+ x = "<mods #{@ns_decl}><name type='personal'>
332
+ <namePart>Alterman, Eric</namePart>
333
+ <displayForm>Eric Alterman</displayForm>
334
+ </name><mods>"
335
+ r = Mods::Record.new.from_str(x)
336
+ r.plain_name.first.display_value.should == 'Eric Alterman'
337
+ end
338
+ it "display_value should not include <namePart type='date'>" do
339
+ @mods_namepart_date.plain_name.first.display_value.should == 'Suzy'
340
+ end
341
+ it "date text should be added to display_value_w_date when it is available" do
342
+ @mods_namepart_date.plain_name.first.display_value_w_date.should == 'Suzy, 1920-'
343
+ end
344
+ it "date text should not be added to display_value_w_dates if dates are already included" do
345
+ x = "<mods #{@ns_decl}><name>
346
+ <namePart>Woolf, Virginia</namePart>
347
+ <namePart type='date'>1882-1941</namePart>
348
+ <displayForm>Woolf, Virginia, 1882-1941</namePart>
349
+ </name></mods>"
350
+ r = Mods::Record.new.from_str(x)
351
+ r.plain_name.first.display_value_w_date.should == 'Woolf, Virginia, 1882-1941'
352
+ end
353
+ context "personal names" do
354
+ before(:all) do
355
+ @d = '1920-2005'
356
+ x = "<mods #{@ns_decl}><name type='personal'>
357
+ <namePart type='given'>John Paul</namePart>
358
+ <namePart type='termsOfAddress'>II</namePart>
359
+ <namePart type='termsOfAddress'>Pope</namePart>
360
+ <namePart type='date'>#{@d}</namePart>
361
+ </name></mods>"
362
+ @pope = Mods::Record.new.from_str(x)
363
+ x = "<mods #{@ns_decl}><name type='personal'>
364
+ <namePart>Crusty</namePart>
365
+ <namePart>The Clown</namePart>
366
+ <namePart type='date'>#{@d}</namePart>
367
+ </name></mods>"
368
+ @pname2 = Mods::Record.new.from_str(x)
369
+ end
370
+ # use the displayForm of a personal name if present
371
+ # if no displayForm, try to make a string from family name and given name "family_name, given_name"
372
+ # otherwise, return all nameParts concatenated together
373
+ # @return Array of Strings, each containing the above described string
374
+ it "should be [family name], [given name] if they are present" do
375
+ x = "<mods #{@ns_decl}><name type='personal'>
376
+ <namePart type='given'>John</namePart>
377
+ <namePart type='family'>Huston</namePart>
378
+ </name></mods>"
379
+ r = Mods::Record.new.from_str(x)
380
+ r.personal_name.first.display_value.should == 'Huston, John'
381
+ @pope.personal_name.first.display_value.should == 'John Paul II, Pope'
382
+ end
383
+ it "should be concatenation of untyped <namePart> elements if there is no family or given name" do
384
+ @pname2.personal_name.first.display_value.should == 'Crusty The Clown'
385
+ end
386
+ it "should include <termOfAddress> elements, in order, comma separated" do
387
+ @pope.personal_name.first.display_value.should == 'John Paul II, Pope'
388
+ end
389
+ it "display_value should not include date" do
390
+ @pope.personal_name.first.display_value.should_not =~ Regexp.new(@d)
391
+ end
392
+ it "date should be included in display_value_w_date" do
393
+ @pope.personal_name.first.display_value_w_date.should == "John Paul II, Pope, #{@d}"
394
+ end
395
+ end
396
+ context "not personal name (e.g. corporate)" do
397
+ it "should be the value of non-date nameParts concatenated" do
398
+ x = "<mods #{@ns_decl}><name type='corporate'>
399
+ <namePart>United States</namePart>
400
+ <namePart>Court of Appeals (2nd Circuit)</namePart>
401
+ </name></mods>"
402
+ r = Mods::Record.new.from_str(x)
403
+ r.corporate_name.first.display_value.should == 'United States Court of Appeals (2nd Circuit)'
404
+ end
405
+ end
406
+ end # WITH namespaces
407
+
408
+ context "WITHOUT namespaces" do
409
+ before(:all) do
410
+ @mods_pname1 = Mods::Record.new.from_str(@pname1_xml.sub(" #{@ns_decl}", ''), false)
411
+ @mods_cname = Mods::Record.new.from_str(@cname_xml.sub(" #{@ns_decl}", ''), false)
412
+ @mods_name = Mods::Record.new.from_str(@name_xml.sub(" #{@ns_decl}", ''), false)
413
+ @mods_namepart_date = Mods::Record.new.from_str(@namepart_xml.sub(" #{@ns_decl}", ''), false)
414
+ end
415
+ it "should be a string value for each name, not an Array" do
416
+ @mods_name.plain_name.first.display_value.should be_an_instance_of(String)
417
+ @mods_name.plain_name.first.display_value_w_date.should be_an_instance_of(String)
418
+ end
419
+ it "should return nil when there is no display_value" do
420
+ x = "<mods><name>
421
+ <namePart></namePart>
422
+ </name></mods>"
423
+ r = Mods::Record.new.from_str(x, false)
424
+ r.plain_name.first.display_value.should == nil
425
+ end
426
+ it "should be applicable to all name term flavors (plain_name, personal_name, corporate_name ...)" do
427
+ @mods_name.plain_name.first.display_value.should_not == nil
428
+ @mods_name.plain_name.first.display_value_w_date.should_not == nil
429
+ @mods_pname1.personal_name.first.display_value.should_not == nil
430
+ @mods_pname1.personal_name.first.display_value_w_date.should_not == nil
431
+ @mods_cname.corporate_name.first.display_value.should_not == nil
432
+ @mods_cname.corporate_name.first.display_value_w_date.should_not == nil
433
+ end
434
+ it "should not include <affiliation> text" do
435
+ @mods_name.plain_name.first.display_value.should_not =~ Regexp.new(@affl)
436
+ end
437
+ it "should not include <description> text" do
438
+ @mods_name.plain_name.first.display_value.should_not =~ Regexp.new(@desc)
439
+ end
440
+ it "should not include <role> info" do
441
+ @mods_name.plain_name.first.display_value.should_not =~ Regexp.new(@role)
442
+ end
443
+ it "should be the value of the <displayForm> subelement if it exists" do
444
+ @mods_pname1.plain_name.first.display_value.should == @disp_form
445
+ x = "<mods><name type='personal'>
446
+ <namePart>Alterman, Eric</namePart>
447
+ <displayForm>Eric Alterman</displayForm>
448
+ </name><mods>"
449
+ r = Mods::Record.new.from_str(x, false)
450
+ r.plain_name.first.display_value.should == 'Eric Alterman'
451
+ end
452
+ it "display_value should not include <namePart type='date'>" do
453
+ @mods_namepart_date.plain_name.first.display_value.should == 'Suzy'
454
+ end
455
+ it "date text should be added to display_value_w_date when it is available" do
456
+ @mods_namepart_date.plain_name.first.display_value_w_date.should == 'Suzy, 1920-'
457
+ end
458
+ it "date text should not be added to display_value_w_dates if dates are already included" do
459
+ x = "<mods><name>
460
+ <namePart>Woolf, Virginia</namePart>
461
+ <namePart type='date'>1882-1941</namePart>
462
+ <displayForm>Woolf, Virginia, 1882-1941</namePart>
463
+ </name></mods>"
464
+ r = Mods::Record.new.from_str(x, false)
465
+ r.plain_name.first.display_value_w_date.should == 'Woolf, Virginia, 1882-1941'
466
+ end
467
+ context "personal names" do
468
+ before(:all) do
469
+ @d = '1920-2005'
470
+ x = "<mods><name type='personal'>
471
+ <namePart type='given'>John Paul</namePart>
472
+ <namePart type='termsOfAddress'>II</namePart>
473
+ <namePart type='termsOfAddress'>Pope</namePart>
474
+ <namePart type='date'>#{@d}</namePart>
475
+ </name></mods>"
476
+ @pope = Mods::Record.new.from_str(x, false)
477
+ x = "<mods><name type='personal'>
478
+ <namePart>Crusty</namePart>
479
+ <namePart>The Clown</namePart>
480
+ <namePart type='date'>#{@d}</namePart>
481
+ </name></mods>"
482
+ @pname2 = Mods::Record.new.from_str(x, false)
483
+ end
484
+ # use the displayForm of a personal name if present
485
+ # if no displayForm, try to make a string from family name and given name "family_name, given_name"
486
+ # otherwise, return all nameParts concatenated together
487
+ # @return Array of Strings, each containing the above described string
488
+ it "should be [family name], [given name] if they are present" do
489
+ x = "<mods><name type='personal'>
490
+ <namePart type='given'>John</namePart>
491
+ <namePart type='family'>Huston</namePart>
492
+ </name></mods>"
493
+ r = Mods::Record.new.from_str(x, false)
494
+ r.personal_name.first.display_value.should == 'Huston, John'
495
+ @pope.personal_name.first.display_value.should == 'John Paul II, Pope'
496
+ end
497
+ it "should be concatenation of untyped <namePart> elements if there is no family or given name" do
498
+ @pname2.personal_name.first.display_value.should == 'Crusty The Clown'
499
+ end
500
+ it "should include <termOfAddress> elements, in order, comma separated" do
501
+ @pope.personal_name.first.display_value.should == 'John Paul II, Pope'
502
+ end
503
+ it "display_value should not include date" do
504
+ @pope.personal_name.first.display_value.should_not =~ Regexp.new(@d)
505
+ end
506
+ it "date should be included in display_value_w_date" do
507
+ @pope.personal_name.first.display_value_w_date.should == "John Paul II, Pope, #{@d}"
508
+ end
509
+ end
510
+ context "not personal name (e.g. corporate)" do
511
+ it "should be the value of non-date nameParts concatenated" do
512
+ x = "<mods><name type='corporate'>
513
+ <namePart>United States</namePart>
514
+ <namePart>Court of Appeals (2nd Circuit)</namePart>
515
+ </name></mods>"
516
+ r = Mods::Record.new.from_str(x, false)
517
+ r.corporate_name.first.display_value.should == 'United States Court of Appeals (2nd Circuit)'
518
+ end
519
+ end
520
+ end # WITHOUT namespaces
521
+ end # display_value and display_value_w_date
522
+
269
523
  context "roles" do
270
524
  before(:all) do
271
525
  @xml_w_code = "<mods #{@ns_decl}><name><namePart>Alfred Hitchock</namePart>
@@ -158,7 +158,7 @@ describe "Mods::Record" do
158
158
  end
159
159
  it "should include a comma when there is both a family and a given name" do
160
160
  @mods_rec.from_str(@all_name_parts)
161
- @mods_rec.personal_names.should include("Family, Given")
161
+ @mods_rec.personal_names.should include("Family, Given Mr.")
162
162
  end
163
163
  it "should include multiple words in a namePart" do
164
164
  @mods_rec.from_str(@given_family)
@@ -170,11 +170,39 @@ describe "Mods::Record" do
170
170
  @mods_rec.personal_names.first.should_not match(/,/)
171
171
  }
172
172
  end
173
- it "should not include terms of address" do
173
+ it "should include terms of address" do
174
174
  @mods_rec.from_str(@all_name_parts)
175
- @mods_rec.personal_names.first.should_not match(/Mr./)
175
+ @mods_rec.personal_names.first.should match(/Mr./)
176
176
  end
177
177
  end # personal_names
178
+
179
+ context "personal_names_w_dates" do
180
+ before(:all) do
181
+ @given_family = '<mods xmlns="http://www.loc.gov/mods/v3"><name type="personal"><namePart type="given">Jorge Luis</namePart>
182
+ <namePart type="family">Borges</namePart></name></mods>'
183
+ @given_family_date = '<mods xmlns="http://www.loc.gov/mods/v3"><name type="personal"><namePart type="given">Zaphod</namePart>
184
+ <namePart type="family">Beeblebrox</namePart>
185
+ <namePart type="date">1912-2362</namePart></name></mods>'
186
+ @all_name_parts = '<mods xmlns="http://www.loc.gov/mods/v3"><name type="personal"><namePart type="given">Given</namePart>
187
+ <namePart type="family">Family</namePart>
188
+ <namePart type="termsOfAddress">Mr.</namePart>
189
+ <namePart type="date">date</namePart></name></mods>'
190
+ end
191
+ it "should return an Array of Strings" do
192
+ @mods_rec.from_str(@given_family_date)
193
+ @mods_rec.personal_names_w_dates.should be_an_instance_of(Array)
194
+ end
195
+ it "should include the date when it is available" do
196
+ @mods_rec.from_str(@given_family_date)
197
+ @mods_rec.personal_names_w_dates.first.should match(/, 1912-2362$/)
198
+ @mods_rec.from_str(@all_name_parts)
199
+ @mods_rec.personal_names_w_dates.first.should match(/, date$/)
200
+ end
201
+ it "should be just the personal_name if no date is available" do
202
+ @mods_rec.from_str(@given_family)
203
+ @mods_rec.personal_names_w_dates.first.should == 'Borges, Jorge Luis'
204
+ end
205
+ end
178
206
 
179
207
  context "corporate_names" do
180
208
  before(:all) do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mods
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.16
4
+ version: 0.0.17
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-12-18 00:00:00.000000000 Z
13
+ date: 2012-12-20 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: nokogiri
@@ -230,7 +230,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
230
230
  version: '0'
231
231
  segments:
232
232
  - 0
233
- hash: -1181909657495840648
233
+ hash: 3977666186634091349
234
234
  required_rubygems_version: !ruby/object:Gem::Requirement
235
235
  none: false
236
236
  requirements:
@@ -239,7 +239,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
239
239
  version: '0'
240
240
  segments:
241
241
  - 0
242
- hash: -1181909657495840648
242
+ hash: 3977666186634091349
243
243
  requirements: []
244
244
  rubyforge_project:
245
245
  rubygems_version: 1.8.24