mods 0.0.19 → 0.0.20

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,4 +1,4 @@
1
- # Represents the Marc Relator Codes mapped to Relators, from http://www.loc.gov/marc/relators/relacode.html
1
+ # Represents the Marc Relator Codes mapped to Relators, from http://www.loc.gov/marc/relators/relacode.html 2012-12
2
2
  # key - Marc Relator code
3
3
  # value - Marc Relator term
4
4
  MARC_RELATOR = {
@@ -414,7 +414,15 @@ module Mods
414
414
  Mods::AUTHORITY_ATTRIBS.each { |attr_name|
415
415
  n.send attr_name, :path => "@#{attr_name}", :accessor => lambda { |a| a.text }
416
416
  }
417
- n.topic :path => 'm:topic' do |n1|
417
+ n.cartographics :path => 'm:cartographics' do |n1|
418
+ n1.scale :path => 'm:scale'
419
+ n1.projection :path => 'm:projection'
420
+ n1.coordinates :path => 'm:coordinates'
421
+ Mods::Subject::CARTOGRAPHICS_CHILD_ELEMENTS.each { |elname|
422
+ n1.send elname, :path => "m:#{elname}"
423
+ }
424
+ end
425
+ n.genre :path => 'm:genre' do |n1|
418
426
  Mods::AUTHORITY_ATTRIBS.each { |attr_name|
419
427
  n1.send attr_name, :path => "@#{attr_name}", :accessor => lambda { |a| a.text }
420
428
  }
@@ -424,18 +432,31 @@ module Mods
424
432
  n1.send attr_name, :path => "@#{attr_name}", :accessor => lambda { |a| a.text }
425
433
  }
426
434
  end
427
- n.temporal :path => 'm:temporal' do |n1|
435
+ n.geographicCode :path => 'm:geographicCode' do |gc|
428
436
  Mods::AUTHORITY_ATTRIBS.each { |attr_name|
429
- n1.send attr_name, :path => "@#{attr_name}", :accessor => lambda { |a| a.text }
437
+ gc.send attr_name, :path => "@#{attr_name}", :accessor => lambda { |a| a.text }
430
438
  }
431
- # date attributes as attributes
432
- Mods::DATE_ATTRIBS.each { |attr_name|
433
- n1.send attr_name, :path => "@#{attr_name}", :accessor => lambda { |a| a.text }
439
+ # convenience method
440
+ gc.translated_value :path => '.', :accessor => lambda { |gc_node|
441
+ code_val ||= gc_node.text
442
+ xval = nil
443
+ if code_val
444
+ case gc_node.authority
445
+ when 'marcgac'
446
+ xval = MARC_GEOGRAPHIC_AREA[code_val]
447
+ when 'marccountry'
448
+ xval = MARC_COUNTRY[code_val]
449
+ end
450
+ end
451
+ xval
434
452
  }
435
453
  end
436
- n.titleInfo :path => 'm:titleInfo' do |t1|
454
+ n.hierarchicalGeographic :path => 'm:hierarchicalGeographic' do |n1|
455
+ Mods::Subject::HIER_GEO_CHILD_ELEMENTS.each { |elname|
456
+ n1.send elname, :path => "m:#{elname}"
457
+ }
437
458
  Mods::AUTHORITY_ATTRIBS.each { |attr_name|
438
- t1.send attr_name, :path => "@#{attr_name}", :accessor => lambda { |a| a.text }
459
+ n1.send attr_name, :path => "@#{attr_name}", :accessor => lambda { |a| a.text }
439
460
  }
440
461
  end
441
462
  # Note: 'name' is used by Nokogiri
@@ -447,33 +468,26 @@ module Mods
447
468
  n.personal_name :path => 'm:name[@type="personal"]'
448
469
  n.corporate_name :path => 'm:name[@type="corporate"]'
449
470
  n.conference_name :path => 'm:name[@type="conference"]'
450
- n.geographicCode :path => 'm:geographicCode' do |g|
471
+ n.occupation :path => 'm:occupation' do |n1|
451
472
  Mods::AUTHORITY_ATTRIBS.each { |attr_name|
452
- g.send attr_name, :path => "@#{attr_name}", :accessor => lambda { |a| a.text }
473
+ n1.send attr_name, :path => "@#{attr_name}", :accessor => lambda { |a| a.text }
453
474
  }
454
475
  end
455
- n.genre :path => 'm:genre' do |n1|
476
+ n.temporal :path => 'm:temporal' do |n1|
456
477
  Mods::AUTHORITY_ATTRIBS.each { |attr_name|
457
478
  n1.send attr_name, :path => "@#{attr_name}", :accessor => lambda { |a| a.text }
458
479
  }
459
- end
460
- n.hierarchicalGeographic :path => 'm:hierarchicalGeographic' do |n1|
461
- Mods::Subject::HIER_GEO_CHILD_ELEMENTS.each { |elname|
462
- n1.send elname, :path => "m:#{elname}"
463
- }
464
- Mods::AUTHORITY_ATTRIBS.each { |attr_name|
480
+ # date attributes as attributes
481
+ Mods::DATE_ATTRIBS.each { |attr_name|
465
482
  n1.send attr_name, :path => "@#{attr_name}", :accessor => lambda { |a| a.text }
466
483
  }
467
484
  end
468
- n.cartographics :path => 'm:cartographics' do |n1|
469
- n1.scale :path => 'm:scale'
470
- n1.projection :path => 'm:projection'
471
- n1.coordinates :path => 'm:coordinates'
472
- Mods::Subject::CARTOGRAPHICS_CHILD_ELEMENTS.each { |elname|
473
- n1.send elname, :path => "m:#{elname}"
485
+ n.titleInfo :path => 'm:titleInfo' do |t1|
486
+ Mods::AUTHORITY_ATTRIBS.each { |attr_name|
487
+ t1.send attr_name, :path => "@#{attr_name}", :accessor => lambda { |a| a.text }
474
488
  }
475
489
  end
476
- n.occupation :path => 'm:occupation' do |n1|
490
+ n.topic :path => 'm:topic' do |n1|
477
491
  Mods::AUTHORITY_ATTRIBS.each { |attr_name|
478
492
  n1.send attr_name, :path => "@#{attr_name}", :accessor => lambda { |a| a.text }
479
493
  }
@@ -954,9 +968,12 @@ module Mods
954
968
  Mods::AUTHORITY_ATTRIBS.each { |attr_name|
955
969
  n.send attr_name, :path => "@#{attr_name}", :accessor => lambda { |a| a.text }
956
970
  }
957
- n.topic :path => 'topic' do |n1|
958
- Mods::AUTHORITY_ATTRIBS.each { |attr_name|
959
- n1.send attr_name, :path => "@#{attr_name}", :accessor => lambda { |a| a.text }
971
+ n.cartographics :path => 'cartographics' do |n1|
972
+ n1.scale :path => 'scale'
973
+ n1.projection :path => 'projection'
974
+ n1.coordinates :path => 'coordinates'
975
+ Mods::Subject::CARTOGRAPHICS_CHILD_ELEMENTS.each { |elname|
976
+ n1.send elname, :path => "#{elname}"
960
977
  }
961
978
  end
962
979
  n.geographic :path => 'geographic' do |n1|
@@ -964,18 +981,36 @@ module Mods
964
981
  n1.send attr_name, :path => "@#{attr_name}", :accessor => lambda { |a| a.text }
965
982
  }
966
983
  end
967
- n.temporal :path => 'temporal' do |n1|
984
+ n.genre :path => 'genre' do |n1|
968
985
  Mods::AUTHORITY_ATTRIBS.each { |attr_name|
969
986
  n1.send attr_name, :path => "@#{attr_name}", :accessor => lambda { |a| a.text }
970
987
  }
971
- # date attributes as attributes
972
- Mods::DATE_ATTRIBS.each { |attr_name|
973
- n1.send attr_name, :path => "@#{attr_name}", :accessor => lambda { |a| a.text }
988
+ end
989
+ n.geographicCode :path => 'geographicCode' do |gc|
990
+ Mods::AUTHORITY_ATTRIBS.each { |attr_name|
991
+ gc.send attr_name, :path => "@#{attr_name}", :accessor => lambda { |a| a.text }
992
+ }
993
+ # convenience method
994
+ gc.translated_value :path => '.', :accessor => lambda { |gc_node|
995
+ code_val ||= gc_node.text
996
+ xval = nil
997
+ if code_val
998
+ case gc_node.authority
999
+ when 'marcgac'
1000
+ xval = MARC_GEOGRAPHIC_AREA[code_val]
1001
+ when 'marccountry'
1002
+ xval = MARC_COUNTRY[code_val]
1003
+ end
1004
+ end
1005
+ xval
974
1006
  }
975
1007
  end
976
- n.titleInfo :path => 'titleInfo' do |t1|
1008
+ n.hierarchicalGeographic :path => 'hierarchicalGeographic' do |n1|
1009
+ Mods::Subject::HIER_GEO_CHILD_ELEMENTS.each { |elname|
1010
+ n1.send elname, :path => "#{elname}"
1011
+ }
977
1012
  Mods::AUTHORITY_ATTRIBS.each { |attr_name|
978
- t1.send attr_name, :path => "@#{attr_name}", :accessor => lambda { |a| a.text }
1013
+ n1.send attr_name, :path => "@#{attr_name}", :accessor => lambda { |a| a.text }
979
1014
  }
980
1015
  end
981
1016
  # Note: 'name' is used by Nokogiri
@@ -987,33 +1022,26 @@ module Mods
987
1022
  n.personal_name :path => 'name[@type="personal"]'
988
1023
  n.corporate_name :path => 'name[@type="corporate"]'
989
1024
  n.conference_name :path => 'name[@type="conference"]'
990
- n.geographicCode :path => 'geographicCode' do |g|
1025
+ n.occupation :path => 'occupation' do |n1|
991
1026
  Mods::AUTHORITY_ATTRIBS.each { |attr_name|
992
- g.send attr_name, :path => "@#{attr_name}", :accessor => lambda { |a| a.text }
1027
+ n1.send attr_name, :path => "@#{attr_name}", :accessor => lambda { |a| a.text }
993
1028
  }
994
1029
  end
995
- n.genre :path => 'genre' do |n1|
1030
+ n.temporal :path => 'temporal' do |n1|
996
1031
  Mods::AUTHORITY_ATTRIBS.each { |attr_name|
997
1032
  n1.send attr_name, :path => "@#{attr_name}", :accessor => lambda { |a| a.text }
998
1033
  }
999
- end
1000
- n.hierarchicalGeographic :path => 'hierarchicalGeographic' do |n1|
1001
- Mods::Subject::HIER_GEO_CHILD_ELEMENTS.each { |elname|
1002
- n1.send elname, :path => "#{elname}"
1003
- }
1004
- Mods::AUTHORITY_ATTRIBS.each { |attr_name|
1034
+ # date attributes as attributes
1035
+ Mods::DATE_ATTRIBS.each { |attr_name|
1005
1036
  n1.send attr_name, :path => "@#{attr_name}", :accessor => lambda { |a| a.text }
1006
1037
  }
1007
1038
  end
1008
- n.cartographics :path => 'cartographics' do |n1|
1009
- n1.scale :path => 'scale'
1010
- n1.projection :path => 'projection'
1011
- n1.coordinates :path => 'coordinates'
1012
- Mods::Subject::CARTOGRAPHICS_CHILD_ELEMENTS.each { |elname|
1013
- n1.send elname, :path => "#{elname}"
1039
+ n.titleInfo :path => 'titleInfo' do |t1|
1040
+ Mods::AUTHORITY_ATTRIBS.each { |attr_name|
1041
+ t1.send attr_name, :path => "@#{attr_name}", :accessor => lambda { |a| a.text }
1014
1042
  }
1015
1043
  end
1016
- n.occupation :path => 'occupation' do |n1|
1044
+ n.topic :path => 'topic' do |n1|
1017
1045
  Mods::AUTHORITY_ATTRIBS.each { |attr_name|
1018
1046
  n1.send attr_name, :path => "@#{attr_name}", :accessor => lambda { |a| a.text }
1019
1047
  }
@@ -65,38 +65,9 @@ module Mods
65
65
  # @param [String] sep - the separator string to insert between multiple values
66
66
  # @return [String] a String representing the value(s) or nil.
67
67
  def term_value messages, sep = ' '
68
- case messages
69
- when Symbol
70
- nodes = send(messages)
71
- when String
72
- nodes = send(messages.to_sym)
73
- when Array
74
- obj = self
75
- messages.each { |msg|
76
- if msg.is_a? Symbol
77
- obj = obj.send(msg)
78
- elsif msg.is_a? String
79
- obj = obj.send(msg.to_sym)
80
- else
81
- raise ArgumentError, "term_value called with Array containing unrecognized class: #{msg.class}, #{messages.inspect}", caller
82
- end
83
- }
84
- nodes = obj
85
- else
86
- raise ArgumentError, "term_value called with unrecognized argument class: #{messages.class}", caller
87
- end
88
-
89
- val = ''
90
- if nodes
91
- nodes.each { |n|
92
- val << sep + n.text unless n.text.empty?
93
- }
94
- end
95
- val.sub!(sep, '')
96
- return nil if val.empty?
97
- val
98
- rescue NoMethodError
99
- raise ArgumentError, "term_value called with unknown argument: #{messages.inspect}", caller
68
+ vals = term_values messages
69
+ return nil if !vals
70
+ val = vals.join sep
100
71
  end
101
72
 
102
73
  # get the values for the terms, as an Array. If there are no values, the result will be nil.
@@ -1,4 +1,4 @@
1
1
  module Mods
2
2
  # this is the Ruby Gem version
3
- VERSION = "0.0.19"
3
+ VERSION = "0.0.20"
4
4
  end
@@ -119,13 +119,13 @@ describe "Mods::Record" do
119
119
  @mods_rec.term_value(:note, ' -|-').should == 'mult1 -|-mult2'
120
120
  end
121
121
  it "should raise an error for an unrecognized message symbol" do
122
- expect { @mods_rec.term_value(:not_there) }.to raise_error(ArgumentError, "term_value called with unknown argument: :not_there")
122
+ expect { @mods_rec.term_value(:not_there) }.to raise_error(ArgumentError, "term_values called with unknown argument: :not_there")
123
123
  end
124
124
  it "should raise an error if the argument is an Array containing non-symbols" do
125
- expect { @mods_rec.term_value([:subject, @mods_rec.subject]) }.to raise_error(ArgumentError, /term_value called with Array containing unrecognized class:.*NodeSet.*/)
125
+ expect { @mods_rec.term_value([:subject, @mods_rec.subject]) }.to raise_error(ArgumentError, /term_values called with Array containing unrecognized class:.*NodeSet.*/)
126
126
  end
127
127
  it "should raise an error if the argument isn't a Symbol or an Array" do
128
- expect { @mods_rec.term_value(@mods_rec.subject) }.to raise_error(ArgumentError, /term_value called with unrecognized argument class:.*NodeSet.*/)
128
+ expect { @mods_rec.term_value(@mods_rec.subject) }.to raise_error(ArgumentError, /term_values called with unrecognized argument class:.*NodeSet.*/)
129
129
  end
130
130
  end
131
131
 
@@ -1,3 +1,5 @@
1
+ # encoding: UTF-8
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe "Mods <subject> Element" do
@@ -22,10 +24,6 @@ describe "Mods <subject> Element" do
22
24
  pending "to be implemented"
23
25
  end
24
26
 
25
- it "should translate the geographicCodes" do
26
- pending "to be implemented"
27
- end
28
-
29
27
  context "subterms for <name> child elements of <subject> element" do
30
28
  before(:all) do
31
29
  @both_types_sub = @mods_rec.from_str("<mods #{@ns_decl}><subject>
@@ -276,7 +274,29 @@ describe "Mods <subject> Element" do
276
274
  @mods_rec.from_str("<mods #{@ns_decl}><subject><geographicCode authority='fake'>f------</geographicCode></subject></mods>")
277
275
  pending "to be implemented"
278
276
  expect { @mods_rec.subject.geographicCode.authority }.to raise_error(/no idea/)
279
- end
277
+ end
278
+ context "translated_value convenience method" do
279
+ it "should be the translation of the code if it is a marcgac code" do
280
+ @mods_rec.from_str("<mods #{@ns_decl}><subject><geographicCode authority='marcgac'>e-er</geographicCode></subject></mods>")
281
+ @mods_rec.subject.geographicCode.translated_value.should == ["Estonia"]
282
+ end
283
+ it "should be the translation of the code if it is a marccountry code" do
284
+ @mods_rec.from_str("<mods #{@ns_decl}><subject><geographicCode authority='marccountry'>mg</geographicCode></subject></mods>")
285
+ @mods_rec.subject.geographicCode.translated_value.should == ["Madagascar"]
286
+ end
287
+ it "should be nil if the code is invalid" do
288
+ @mods_rec.from_str("<mods #{@ns_decl}><subject><geographicCode authority='marcgac'>zzz</geographicCode></subject></mods>")
289
+ @mods_rec.subject.geographicCode.translated_value.size.should == 0
290
+ end
291
+ it "should be nil if we don't have a translation for the authority" do
292
+ @mods_rec.from_str("<mods #{@ns_decl}><subject><geographicCode authority='iso3166'>zzz</geographicCode></subject></mods>")
293
+ @mods_rec.subject.geographicCode.translated_value.size.should == 0
294
+ end
295
+ it "should work with non-ascii characters" do
296
+ @mods_rec.from_str("<mods #{@ns_decl}><subject><geographicCode authority='marccountry'>co</geographicCode></subject></mods>")
297
+ @mods_rec.subject.geographicCode.translated_value.should == ["Curaçao"]
298
+ end
299
+ end
280
300
  end # <geographicCode>
281
301
 
282
302
  context "<titleInfo> child element" do
@@ -600,7 +620,29 @@ describe "Mods <subject> Element" do
600
620
  @mods_rec.from_str("<mods><subject><geographicCode authority='fake'>f------</geographicCode></subject></mods>", false)
601
621
  pending "to be implemented"
602
622
  expect { @mods_rec.subject.geographicCode.authority }.to raise_error(/no idea/)
603
- end
623
+ end
624
+ context "translated_value convenience method" do
625
+ it "should be the translation of the code if it is a marcgac code" do
626
+ @mods_rec.from_str("<mods><subject><geographicCode authority='marcgac'>e-er</geographicCode></subject></mods>", false)
627
+ @mods_rec.subject.geographicCode.translated_value.should == ["Estonia"]
628
+ end
629
+ it "should be the translation of the code if it is a marccountry code" do
630
+ @mods_rec.from_str("<mods><subject><geographicCode authority='marccountry'>mg</geographicCode></subject></mods>", false)
631
+ @mods_rec.subject.geographicCode.translated_value.should == ["Madagascar"]
632
+ end
633
+ it "should be empty if the code is invalid" do
634
+ @mods_rec.from_str("<mods><subject><geographicCode authority='marcgac'>zzz</geographicCode></subject></mods>", false)
635
+ @mods_rec.subject.geographicCode.translated_value.size.should == 0
636
+ end
637
+ it "should be empty if we don't have a translation for the authority" do
638
+ @mods_rec.from_str("<mods><subject><geographicCode authority='iso3166'>zzz</geographicCode></subject></mods>", false)
639
+ @mods_rec.subject.geographicCode.translated_value.size.should == 0
640
+ end
641
+ it "should work with non-ascii characters" do
642
+ @mods_rec.from_str("<mods><subject><geographicCode authority='marccountry'>co</geographicCode></subject></mods>", false)
643
+ @mods_rec.subject.geographicCode.translated_value.should == ["Curaçao"]
644
+ end
645
+ end
604
646
  end # <geographicCode>
605
647
 
606
648
  context "<titleInfo> child element" 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.19
4
+ version: 0.0.20
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: 2013-01-03 00:00:00.000000000 Z
13
+ date: 2013-01-04 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: nokogiri
@@ -193,6 +193,8 @@ files:
193
193
  - Rakefile
194
194
  - lib/mods.rb
195
195
  - lib/mods/constants.rb
196
+ - lib/mods/marc_country_codes.rb
197
+ - lib/mods/marc_geo_area_codes.rb
196
198
  - lib/mods/marc_relator_codes.rb
197
199
  - lib/mods/name.rb
198
200
  - lib/mods/nom_terminology.rb
@@ -230,7 +232,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
230
232
  version: '0'
231
233
  segments:
232
234
  - 0
233
- hash: -103128391758447050
235
+ hash: 2201065419699116164
234
236
  required_rubygems_version: !ruby/object:Gem::Requirement
235
237
  none: false
236
238
  requirements:
@@ -239,7 +241,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
239
241
  version: '0'
240
242
  segments:
241
243
  - 0
242
- hash: -103128391758447050
244
+ hash: 2201065419699116164
243
245
  requirements: []
244
246
  rubyforge_project:
245
247
  rubygems_version: 1.8.24