stanford-mods 0.0.23 → 0.0.24

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,6 +1,6 @@
1
1
  module Stanford
2
2
  module Mods
3
3
  # this is the Ruby Gem version
4
- VERSION = "0.0.23"
4
+ VERSION = "0.0.24"
5
5
  end
6
6
  end
@@ -0,0 +1,103 @@
1
+ # encoding: UTF-8
2
+ require 'spec_helper'
3
+
4
+ describe "Format field from Searchworks mixin for Stanford::Mods::Record" do
5
+
6
+ before(:all) do
7
+ @smods_rec = Stanford::Mods::Record.new
8
+ @ns_decl = "xmlns='#{Mods::MODS_NS}'"
9
+ end
10
+
11
+ it "should check genre as part of deciding format" do
12
+ m = "<mods #{@ns_decl}><typeOfResource>text</typeOfResouce><genre>thesis</genre></mods>"
13
+ @smods_rec = Stanford::Mods::Record.new
14
+ @smods_rec.from_str(m)
15
+ @smods_rec.format.should == ['Thesis']
16
+ end
17
+
18
+ it 'should work for datasets' do
19
+ m = "<mods #{@ns_decl}><typeOfResource>software, multimedia</typeOfResouce></mods>"
20
+ @smods_rec = Stanford::Mods::Record.new
21
+ @smods_rec.from_str(m)
22
+ @smods_rec.format.should == ['Computer File']
23
+ end
24
+
25
+ it 'should work for books' do
26
+ m = "<mods #{@ns_decl}><typeOfResource>text</typeOfResouce><originInfo><issuance>monographic</issueance></originInfo></mods>"
27
+ @smods_rec = Stanford::Mods::Record.new
28
+ @smods_rec.from_str(m)
29
+ @smods_rec.format.should == ['Book']
30
+ end
31
+
32
+ it "should work for a hydrus journal article" do
33
+ m = "<mods #{@ns_decl}><typeOfResource>text</typeOfResouce><genre>article</genre></mods>"
34
+ @smods_rec = Stanford::Mods::Record.new
35
+ @smods_rec.from_str(m)
36
+ @smods_rec.format.should == ['Journal/Periodical']
37
+ end
38
+
39
+ it "should work for image" do
40
+ m = "<mods #{@ns_decl}><typeOfResource>still image</typeOfResouce></mods>"
41
+ @smods_rec = Stanford::Mods::Record.new
42
+ @smods_rec.from_str(m)
43
+ @smods_rec.format.should == ['Image']
44
+ end
45
+
46
+ context "Hydrus mappings per GRYPHONDOR-207" do
47
+ it "should give a format of Computer File for <genre>game</genre> and <typeOfResource>software, multimedia</typeOfResouce>" do
48
+ m = "<mods #{@ns_decl}><genre>game</genre><typeOfResource>software, multimedia</typeOfResouce></mods>"
49
+ @smods_rec = Stanford::Mods::Record.new
50
+ @smods_rec.from_str(m)
51
+ @smods_rec.format.should == ['Computer File']
52
+ end
53
+ it "should give a format of Video for <genre>motion picture</genre> and <typeOfResource>moving image</typeOfResouce>" do
54
+ m = "<mods #{@ns_decl}><genre>motion picture</genre><typeOfResource>moving image</typeOfResouce></mods>"
55
+ @smods_rec = Stanford::Mods::Record.new
56
+ @smods_rec.from_str(m)
57
+ @smods_rec.format.should == ['Video']
58
+ end
59
+ it "should give a format of Sound Recording for <genre>sound</genre> and <typeOfResource>sound recording-nonmusical</typeOfResouce>" do
60
+ m = "<mods #{@ns_decl}><genre>sound</genre><typeOfResource>sound recording-nonmusical</typeOfResouce></mods>"
61
+ @smods_rec = Stanford::Mods::Record.new
62
+ @smods_rec.from_str(m)
63
+ @smods_rec.format.should == ['Sound Recording']
64
+ end
65
+ it "should give a format of Conference Proceedings for <genre>conference publication</genre> and <typeOfResource>text</typeOfResouce>" do
66
+ m = "<mods #{@ns_decl}><genre>conference publication</genre><typeOfResource>text</typeOfResouce></mods>"
67
+ @smods_rec = Stanford::Mods::Record.new
68
+ @smods_rec.from_str(m)
69
+ @smods_rec.format.should == ['Conference Proceedings']
70
+ end
71
+ it "should give a format of Book for <genre>technical report</genre> and <typeOfResource>text</typeOfResouce>" do
72
+ m = "<mods #{@ns_decl}><genre>technical report</genre><typeOfResource>text</typeOfResouce></mods>"
73
+ @smods_rec = Stanford::Mods::Record.new
74
+ @smods_rec.from_str(m)
75
+ @smods_rec.format.should == ['Book']
76
+ end
77
+ end
78
+
79
+ # Student Project Reports: spec via email from Vitus, August 16, 2013
80
+ it "should give a format of Other for <genre>student project report</genre> and <typeOfResource>text</typeOfResouce>" do
81
+ m = "<mods #{@ns_decl}><genre>student project report</genre><typeOfResource>text</typeOfResouce></mods>"
82
+ @smods_rec = Stanford::Mods::Record.new
83
+ @smods_rec.from_str(m)
84
+ @smods_rec.format.should == ['Other']
85
+ end
86
+
87
+ it "should give a format of Music - Score for <typeOfResource>notated music</typeOfResouce>" do
88
+ m = "<mods #{@ns_decl}><typeOfResource>notated music</typeOfResouce></mods>"
89
+ @smods_rec = Stanford::Mods::Record.new
90
+ @smods_rec.from_str(m)
91
+ @smods_rec.format.should == ['Music - Score']
92
+ end
93
+
94
+ it "should return nothing if there is no format info" do
95
+ m = "<mods #{@ns_decl}><originInfo>
96
+ <dateCreated>1904</dateCreated>
97
+ </originInfo></mods>"
98
+ @smods_rec = Stanford::Mods::Record.new
99
+ @smods_rec.from_str(m)
100
+ @smods_rec.format.should == []
101
+ end
102
+
103
+ end
@@ -0,0 +1,236 @@
1
+ # encoding: UTF-8
2
+ require 'spec_helper'
3
+
4
+ describe "Date methods in Searchworks mixin for Stanford::Mods::Record" do
5
+
6
+ before(:all) do
7
+ @smods_rec = Stanford::Mods::Record.new
8
+ @ns_decl = "xmlns='#{Mods::MODS_NS}'"
9
+ end
10
+
11
+ context "pub_dates" do
12
+ it "should choose the first date" do
13
+ m = "<mods #{@ns_decl}><originInfo>
14
+ <dateCreated>1904</dateCreated>
15
+ <dateCreated>1904</dateCreated>
16
+ <dateIssued>1906</dateIssued>
17
+ </originInfo></mods>"
18
+ @smods_rec = Stanford::Mods::Record.new
19
+ @smods_rec.from_str(m)
20
+ @smods_rec.pub_dates.should == ['1906','1904','1904']
21
+ end
22
+ end
23
+
24
+ context "pub_date" do
25
+ it "should choose the first date" do
26
+ m = "<mods #{@ns_decl}><originInfo>
27
+ <dateCreated>1904</dateCreated>
28
+ </originInfo></mods>"
29
+ @smods_rec = Stanford::Mods::Record.new
30
+ @smods_rec.from_str(m)
31
+ @smods_rec.pub_date.should == '1904'
32
+ end
33
+ it "should parse a date" do
34
+ m = "<mods #{@ns_decl}><originInfo>
35
+ <dateCreated>Aug. 3rd, 1886</dateCreated>
36
+ </originInfo></mods>"
37
+ @smods_rec = Stanford::Mods::Record.new
38
+ @smods_rec.from_str(m)
39
+ @smods_rec.pub_date.should == '1886'
40
+ end
41
+ it "should remove question marks and brackets" do
42
+ m = "<mods #{@ns_decl}><originInfo>
43
+ <dateCreated>Aug. 3rd, [18]86?</dateCreated>
44
+ </originInfo></mods>"
45
+ @smods_rec = Stanford::Mods::Record.new
46
+ @smods_rec.from_str(m)
47
+ @smods_rec.pub_date.should == '1886'
48
+ end
49
+ it 'should handle an s after the decade' do
50
+ m = "<mods #{@ns_decl}><originInfo>
51
+ <dateCreated>early 1890s</dateCreated>
52
+ </originInfo></mods>"
53
+ @smods_rec = Stanford::Mods::Record.new
54
+ @smods_rec.from_str(m)
55
+ @smods_rec.pub_date.should == '1890'
56
+ end
57
+ it 'should choose a date ending with CE if there are multiple dates' do
58
+ m = "<mods #{@ns_decl}><originInfo><dateIssued>7192 AM (li-Adam) / 1684 CE</dateIssued><issuance>monographic</issuance></originInfo>"
59
+ @smods_rec = Stanford::Mods::Record.new
60
+ @smods_rec.from_str(m)
61
+ @smods_rec.pub_date.should == '1684'
62
+ end
63
+ it 'should handle hyphenated range dates' do
64
+ m = "<mods #{@ns_decl}><originInfo><dateIssued>1282 AH / 1865-6 CE</dateIssued><issuance>monographic</issuance></originInfo>"
65
+ @smods_rec = Stanford::Mods::Record.new
66
+ @smods_rec.from_str(m)
67
+ @smods_rec.pub_date.should == '1865'
68
+ end
69
+ it 'should work with multiple 4 digit dates' do
70
+ m = "<mods #{@ns_decl}><originInfo><dateCreated>Text dated June 4, 1594; miniatures added by 1596</dateCreated></originInfo>"
71
+ @smods_rec = Stanford::Mods::Record.new
72
+ @smods_rec.from_str(m)
73
+ @smods_rec.pub_date.should == '1594'
74
+ end
75
+ it 'should work on 3 digit BC dates' do
76
+ m = "<mods #{@ns_decl}><originInfo><dateCreated>300 B.C.</dateCreated></originInfo>"
77
+ @smods_rec = Stanford::Mods::Record.new
78
+ @smods_rec.from_str(m)
79
+ @smods_rec.pub_year.should == '-700'
80
+ @smods_rec.pub_date.should == '-700'
81
+ @smods_rec.pub_date_sort.should =='-700'
82
+ @smods_rec.pub_date_facet.should == '300 B.C.'
83
+ end
84
+ it 'should handle century based dates' do
85
+ m = "<mods #{@ns_decl}><originInfo><dateIssued>13th century AH / 19th CE</dateIssued><issuance>monographic</issuance></originInfo>"
86
+ @smods_rec = Stanford::Mods::Record.new
87
+ @smods_rec.from_str(m)
88
+ @smods_rec.pub_date_facet.should == '19th century'
89
+ @smods_rec.pub_date_sort.should =='1800'
90
+ @smods_rec.pub_date.should == '18--'
91
+ end
92
+ it 'should handle multiple CE dates' do
93
+ m = "<mods #{@ns_decl}><originInfo><dateIssued>6 Dhu al-Hijjah 923 AH / 1517 CE -- 7 Rabi I 924 AH / 1518 CE</dateIssued><issuance>monographic</issuance></originInfo>"
94
+ @smods_rec = Stanford::Mods::Record.new
95
+ @smods_rec.from_str(m)
96
+ @smods_rec.pub_date.should == '1517'
97
+ @smods_rec.pub_date_sort.should =='1517'
98
+ @smods_rec.pub_date_facet.should == '1517'
99
+ end
100
+ it 'should handle this case from walters' do
101
+ m = "<mods #{@ns_decl}><originInfo><dateIssued>Late 14th or early 15th century CE</dateIssued><issuance>monographic</issuance></originInfo>"
102
+ @smods_rec = Stanford::Mods::Record.new
103
+ @smods_rec.from_str(m)
104
+ @smods_rec.pub_date.should == '14--'
105
+ @smods_rec.pub_date_sort.should =='1400'
106
+ @smods_rec.pub_date_facet.should == '15th century'
107
+ end
108
+ it 'should work on 3 digit dates' do
109
+ m = "<mods #{@ns_decl}><originInfo><dateIssued>966 CE</dateIssued><issuance>monographic</issuance></originInfo>"
110
+ @smods_rec = Stanford::Mods::Record.new
111
+ @smods_rec.from_str(m)
112
+ @smods_rec.pub_date.should == '966'
113
+ @smods_rec.pub_date_sort.should =='0966'
114
+ @smods_rec.pub_date_facet.should == '966'
115
+ end
116
+ it 'should work on 3 digit dates' do
117
+ m = "<mods #{@ns_decl}><originInfo><dateIssued>3rd century AH / 9th CE</dateIssued><issuance>monographic</issuance></originInfo>"
118
+ @smods_rec = Stanford::Mods::Record.new
119
+ @smods_rec.from_str(m)
120
+
121
+ @smods_rec.pub_date.should == '8--'
122
+ @smods_rec.pub_date_sort.should =='0800'
123
+ @smods_rec.pub_date_facet.should == '9th century'
124
+ end
125
+ end # pub_date
126
+
127
+ context "dates with u notation (198u, 19uu)" do
128
+ context "single digit u notation (198u)" do
129
+ before(:all) do
130
+ m = "<mods #{@ns_decl}>
131
+ <originInfo>
132
+ <dateIssued encoding=\"marc\" point=\"start\" keyDate=\"yes\">198u</dateIssued>
133
+ <dateIssued encoding=\"marc\" point=\"end\">9999</dateIssued>
134
+ </originInfo></mods>"
135
+ @smods_rec = Stanford::Mods::Record.new
136
+ @smods_rec.from_str(m)
137
+ end
138
+ it "get_u_year recognizes notation" do
139
+ dates = ["198u", "9999"]
140
+ uDate = @smods_rec.get_u_year dates
141
+ uDate.should eql("1980")
142
+ end
143
+ it 'pub_date: 198u = 1980' do
144
+ @smods_rec.pub_date.should == '1980'
145
+ end
146
+ it "pub_date_sort: 198u = 1980" do
147
+ @smods_rec.pub_date_sort.should =='1980'
148
+ end
149
+ it "pub_date_facet: 198u = 1980" do
150
+ @smods_rec.pub_date_facet.should == '1980'
151
+ end
152
+ end
153
+ context "double digit u notation (19uu)" do
154
+ before(:all) do
155
+ m = "<mods #{@ns_decl}>
156
+ <originInfo>
157
+ <dateIssued encoding=\"marc\" point=\"start\" keyDate=\"yes\">19uu</dateIssued>
158
+ <dateIssued encoding=\"marc\" point=\"end\">9999</dateIssued>
159
+ </originInfo></mods>"
160
+ @smods_rec = Stanford::Mods::Record.new
161
+ @smods_rec.from_str(m)
162
+ end
163
+ it "get_u_year recognizes notation" do
164
+ dates = ["19uu", "9999"]
165
+ uDate = @smods_rec.get_u_year dates
166
+ uDate.should eql("19--")
167
+ end
168
+ it 'pub_date: 19uu = 19--' do
169
+ @smods_rec.pub_date.should == '19--'
170
+ end
171
+ it "pub_date_sort: 19uu = 1900" do
172
+ @smods_rec.pub_date_sort.should =='1900'
173
+ end
174
+ it "pub_date_facet: 19uu = 20th century" do
175
+ @smods_rec.pub_date_facet.should == '20th century'
176
+ end
177
+ end
178
+ end # u notation
179
+
180
+
181
+
182
+
183
+ context 'pub_date_sort' do
184
+ before :all do
185
+ m = "<mods #{@ns_decl}><originInfo>
186
+ <dateCreated>Aug. 3rd, 1886</dateCreated>
187
+ </originInfo></mods>"
188
+ @smods_rec = Stanford::Mods::Record.new
189
+ @smods_rec.from_str(m)
190
+ end
191
+ it 'should work on normal dates' do
192
+ @smods_rec.stub(:pub_date).and_return('1945')
193
+ @smods_rec.pub_date_sort.should == '1945'
194
+ end
195
+ it 'should work on 3 digit dates' do
196
+ @smods_rec.stub(:pub_date).and_return('945')
197
+ @smods_rec.pub_date_sort.should == '0945'
198
+ end
199
+ it 'should work on century dates' do
200
+ @smods_rec.stub(:pub_date).and_return('16--')
201
+ @smods_rec.pub_date_sort.should == '1600'
202
+ end
203
+ it 'should work on 3 digit century dates' do
204
+ @smods_rec.stub(:pub_date).and_return('9--')
205
+ @smods_rec.pub_date_sort.should == '0900'
206
+ end
207
+ end
208
+
209
+ context "pub_date_groups" do
210
+ it 'should generate the groups' do
211
+ m = "<mods #{@ns_decl}><originInfo>
212
+ <dateCreated>1904</dateCreated>
213
+ </originInfo></mods>"
214
+ @smods_rec = Stanford::Mods::Record.new
215
+ @smods_rec.from_str(m)
216
+ @smods_rec.pub_date_groups(1904).should == ['More than 50 years ago']
217
+ end
218
+ it 'should work for a modern date too' do
219
+ m = "<mods #{@ns_decl}><originInfo>
220
+ <dateCreated>1904</dateCreated>
221
+ </originInfo></mods>"
222
+ @smods_rec = Stanford::Mods::Record.new
223
+ @smods_rec.from_str(m)
224
+ @smods_rec.pub_date_groups(2013).should == ["This year"]
225
+ end
226
+ it 'should work ok given a nil date' do
227
+ m = "<mods #{@ns_decl}><originInfo>
228
+ <dateCreated>1904</dateCreated>
229
+ </originInfo></mods>"
230
+ @smods_rec = Stanford::Mods::Record.new
231
+ @smods_rec.from_str(m)
232
+ @smods_rec.pub_date_groups(nil).should == nil
233
+ end
234
+ end #context pub date groups
235
+
236
+ end
@@ -115,6 +115,7 @@ describe "Searchworks mixin for Stanford::Mods::Record" do
115
115
  m = "<mods #{@ns_decl}><titleInfo><title>Jerk</title><subTitle>A Tale of Tourettes</subTitle><nonSort>The</nonSort></titleInfo></mods>"
116
116
  @smods_rec.from_str m
117
117
  end
118
+
118
119
  context "short title (for title_245a_search, title_245a_display) " do
119
120
  it "should call :short_titles" do
120
121
  @smods_rec.should_receive(:short_titles) # in Mods gem
@@ -124,6 +125,7 @@ describe "Searchworks mixin for Stanford::Mods::Record" do
124
125
  @smods_rec.sw_short_title.should == 'The Jerk'
125
126
  end
126
127
  end
128
+
127
129
  context "full title (for title_245_search, title_display, title_full_display)" do
128
130
  it "should call :full_titles" do
129
131
  @smods_rec.should_receive(:full_titles) # in Mods gem
@@ -140,6 +142,7 @@ describe "Searchworks mixin for Stanford::Mods::Record" do
140
142
  @smods_rec.sw_full_title.should == 'Pius V. Saint, [Michaele Gisleri)'
141
143
  end
142
144
  end
145
+
143
146
  context "additional titles (for title_variant_search)" do
144
147
  before(:all) do
145
148
  m = "<mods #{@ns_decl}>
@@ -170,6 +173,7 @@ describe "Searchworks mixin for Stanford::Mods::Record" do
170
173
  @addl_titles = @smods_rec.sw_addl_titles
171
174
  end
172
175
  end
176
+
173
177
  context "sort title" do
174
178
  it "should be a String" do
175
179
  @smods_rec.sw_sort_title.should be_an_instance_of(String)
@@ -0,0 +1,384 @@
1
+ # encoding: UTF-8
2
+ require 'spec_helper'
3
+
4
+ describe "Searchworks mixin for Stanford::Mods::Record" do
5
+
6
+ before(:all) do
7
+ @smods_rec = Stanford::Mods::Record.new
8
+ @ns_decl = "xmlns='#{Mods::MODS_NS}'"
9
+ end
10
+
11
+ context "sw subject raw methods" do
12
+ before(:all) do
13
+ @genre = 'genre top level'
14
+ @cart_coord = '6 00 S, 71 30 E'
15
+ @s_genre = 'genre in subject'
16
+ @geo = 'Somewhere'
17
+ @geo_code = 'us'
18
+ @hier_geo_country = 'France'
19
+ @s_name = 'name in subject'
20
+ @occupation = 'worker bee'
21
+ @temporal = 'temporal'
22
+ @s_title = 'title in subject'
23
+ @topic = 'topic'
24
+ m = "<mods #{@ns_decl}>
25
+ <genre>#{@genre}</genre>
26
+ <subject><cartographics><coordinates>#{@cart_coord}</coordinates></cartographics></subject>
27
+ <subject><genre>#{@s_genre}</genre></subject>
28
+ <subject><geographic>#{@geo}</geographic></subject>
29
+ <subject><geographicCode authority='iso3166'>#{@geo_code}</geographicCode></subject>
30
+ <subject><hierarchicalGeographic><country>#{@hier_geo_country}</country></hierarchicalGeographic></subject>
31
+ <subject><name><namePart>#{@s_name}</namePart></name></subject>
32
+ <subject><occupation>#{@occupation}</occupation></subject>
33
+ <subject><temporal>#{@temporal}</temporal></subject>
34
+ <subject><titleInfo><title>#{@s_title}</title></titleInfo></subject>
35
+ <subject><topic>#{@topic}</topic></subject>
36
+ </mods>"
37
+ @smods_rec.from_str m
38
+ @sw_geographic_search = @smods_rec.sw_geographic_search
39
+ @sw_subject_titles = @smods_rec.sw_subject_titles
40
+ @sw_subject_names = @smods_rec.sw_subject_names
41
+ end
42
+
43
+ context "sw_subject_names" do
44
+ it "should contain <subject><name><namePart> values" do
45
+ @sw_subject_names.should include(@s_name)
46
+ end
47
+ it "should not contain non-name subject subelements" do
48
+ @sw_subject_names.should_not include(@cart_coord)
49
+ @sw_subject_names.should_not include(@s_genre)
50
+ @sw_subject_names.should_not include(@geo)
51
+ @sw_subject_names.should_not include(@geo_code)
52
+ @sw_subject_names.should_not include(@hier_geo_country)
53
+ @sw_subject_names.should_not include(@occupation)
54
+ @sw_subject_names.should_not include(@temporal)
55
+ @sw_subject_names.should_not include(@topic)
56
+ @sw_subject_names.should_not include(@s_title)
57
+ end
58
+ it "should not contain subject/name/role" do
59
+ m = "<mods #{@ns_decl}>
60
+ <subject><name type='personal'>
61
+ <namePart>Alterman, Eric</namePart>
62
+ <displayForm>Eric Alterman</displayForm>
63
+ <role>
64
+ <roleTerm type='text'>creator</roleTerm>
65
+ <roleTerm type='code'>cre</roleTerm>
66
+ </role>
67
+ </name></subject></mods>"
68
+ @smods_rec.from_str m
69
+ @smods_rec.sw_subject_names.find { |sn| sn =~ /cre/ }.should == nil
70
+ end
71
+ it "should not contain subject/name/affiliation" do
72
+ m = "<mods #{@ns_decl}>
73
+ <subject><name type='personal'>
74
+ <namePart type='termsOfAddress'>Dr.</namePart>
75
+ <namePart>Brown, B. F.</namePart>
76
+ <affiliation>Chemistry Dept., American University</affiliation>
77
+ </name></subject></mods>"
78
+ @smods_rec.from_str m
79
+ @smods_rec.sw_subject_names.find { |sn| sn =~ /Chemistry/ }.should == nil
80
+ end
81
+ it "should not contain subject/name/description" do
82
+ m = "<mods #{@ns_decl}>
83
+ <subject><name type='personal'>
84
+ <namePart>Abrams, Michael</namePart>
85
+ <description>American artist, 20th c.</description>
86
+ </name></subject></mods>"
87
+ @smods_rec.from_str m
88
+ @smods_rec.sw_subject_names.find { |sn| sn =~ /artist/ }.should == nil
89
+ end
90
+ it "should not include top level name element" do
91
+ m = "<mods #{@ns_decl}>
92
+ <name type='personal'>
93
+ <namePart>Abrams, Michael</namePart>
94
+ <description>American artist, 20th c.</description>
95
+ </name></mods>"
96
+ @smods_rec.from_str m
97
+ @smods_rec.sw_subject_names.should == []
98
+ end
99
+ it "should have one value for each name element" do
100
+ m = "<mods #{@ns_decl}>
101
+ <subject>
102
+ <name><namePart>first</namePart></name>
103
+ <name><namePart>second</namePart></name>
104
+ </subject>
105
+ <subject>
106
+ <name><namePart>third</namePart></name>
107
+ </subject>
108
+ </mods>"
109
+ @smods_rec.from_str m
110
+ @smods_rec.sw_subject_names.should == ['first', 'second', 'third']
111
+ end
112
+ it "should be an empty Array if there are no values in the mods" do
113
+ m = "<mods #{@ns_decl}><note>notit</note></mods>"
114
+ @smods_rec.from_str m
115
+ @smods_rec.sw_subject_names.should == []
116
+ end
117
+ it "should be an empty Array if there are empty values in the mods" do
118
+ m = "<mods #{@ns_decl}><subject><name><namePart/></name></subject><note>notit</note></mods>"
119
+ @smods_rec.from_str m
120
+ @smods_rec.sw_subject_names.should == []
121
+ end
122
+ context "combining subelements" do
123
+ before(:all) do
124
+ m = "<mods #{@ns_decl}>
125
+ <subject>
126
+ <name>
127
+ <namePart>first</namePart>
128
+ <namePart>second</namePart>
129
+ </name>
130
+ </subject>
131
+ </mods>"
132
+ @smods_rec.from_str m
133
+ end
134
+ it "uses a ', ' as the separator by default" do
135
+ @smods_rec.sw_subject_names.should == ['first, second']
136
+ end
137
+ it "honors any string value passed in for the separator" do
138
+ @smods_rec.sw_subject_names(' --').should == ['first --second']
139
+ end
140
+ end
141
+ end # sw_subject_names
142
+
143
+ context "sw_subject_titles" do
144
+ it "should contain <subject><titleInfo> subelement values" do
145
+ @sw_subject_titles.should include(@s_title)
146
+ end
147
+ it "should not contain non-name subject subelements" do
148
+ @sw_subject_titles.should_not include(@cart_coord)
149
+ @sw_subject_titles.should_not include(@s_genre)
150
+ @sw_subject_titles.should_not include(@geo)
151
+ @sw_subject_titles.should_not include(@geo_code)
152
+ @sw_subject_titles.should_not include(@hier_geo_country)
153
+ @sw_subject_titles.should_not include(@s_name)
154
+ @sw_subject_titles.should_not include(@occupation)
155
+ @sw_subject_titles.should_not include(@temporal)
156
+ @sw_subject_titles.should_not include(@topic)
157
+ end
158
+ it "should not include top level titleInfo element" do
159
+ m = "<mods #{@ns_decl}><titleInfo><title>Oklahoma</title></titleInfo></mods>"
160
+ @smods_rec.from_str m
161
+ @smods_rec.sw_subject_titles.should == []
162
+ end
163
+ it "should have one value for each titleInfo element" do
164
+ m = "<mods #{@ns_decl}>
165
+ <subject>
166
+ <titleInfo><title>first</title></titleInfo>
167
+ <titleInfo><title>second</title></titleInfo>
168
+ </subject>
169
+ <subject>
170
+ <titleInfo><title>third</title></titleInfo>
171
+ </subject>
172
+ </mods>"
173
+ @smods_rec.from_str m
174
+ @smods_rec.sw_subject_titles.should == ['first', 'second', 'third']
175
+ end
176
+ it "should be an empty Array if there are no values in the mods" do
177
+ m = "<mods #{@ns_decl}><note>notit</note></mods>"
178
+ @smods_rec.from_str m
179
+ @smods_rec.sw_subject_titles.should == []
180
+ end
181
+ it "should be an empty Array if there are empty values in the mods" do
182
+ m = "<mods #{@ns_decl}><subject><titleInfo><title/></titleInfo></subject><note>notit</note></mods>"
183
+ @smods_rec.from_str m
184
+ @smods_rec.sw_subject_titles.should == []
185
+ end
186
+ context "combining subelements" do
187
+ before(:all) do
188
+ m = "<mods #{@ns_decl}>
189
+ <subject>
190
+ <titleInfo>
191
+ <title>first</title>
192
+ <subTitle>second</subTitle>
193
+ </titleInfo>
194
+ </subject>
195
+ </mods>"
196
+ @smods_rec.from_str m
197
+ end
198
+ it "uses a ' ' as the separator by default" do
199
+ @smods_rec.sw_subject_titles.should == ['first second']
200
+ end
201
+ it "honors any string value passed in for the separator" do
202
+ @smods_rec.sw_subject_titles(' --').should == ['first --second']
203
+ end
204
+ it "includes all subelements in the order of occurrence" do
205
+ m = "<mods #{@ns_decl}>
206
+ <subject>
207
+ <titleInfo>
208
+ <partName>1</partName>
209
+ <nonSort>2</nonSort>
210
+ <partNumber>3</partNumber>
211
+ <title>4</title>
212
+ <subTitle>5</subTitle>
213
+ </titleInfo>
214
+ </subject>
215
+ </mods>"
216
+ @smods_rec.from_str m
217
+ @smods_rec.sw_subject_titles.should == ['1 2 3 4 5']
218
+ end
219
+ end
220
+ end # sw_subject_titles
221
+
222
+
223
+ context "sw_geographic_search" do
224
+ it "should contain subject <geographic> subelement data" do
225
+ @sw_geographic_search.should include(@geo)
226
+ end
227
+ it "should contain subject <hierarchicalGeographic> subelement data" do
228
+ @sw_geographic_search.should include(@hier_geo_country)
229
+ end
230
+ it "should contain translation of <geographicCode> subelement data with translated authorities" do
231
+ m = "<mods #{@ns_decl}><subject><geographicCode authority='marcgac'>e-er</geographicCode></subject></mods>"
232
+ @smods_rec.from_str m
233
+ @smods_rec.sw_geographic_search.should include('Estonia')
234
+ end
235
+ it "should not contain other subject element data" do
236
+ @sw_geographic_search.should_not include(@genre)
237
+ @sw_geographic_search.should_not include(@cart_coord)
238
+ @sw_geographic_search.should_not include(@s_genre)
239
+ @sw_geographic_search.should_not include(@s_name)
240
+ @sw_geographic_search.should_not include(@occupation)
241
+ @sw_geographic_search.should_not include(@temporal)
242
+ @sw_geographic_search.should_not include(@topic)
243
+ @sw_geographic_search.should_not include(@s_title)
244
+ end
245
+ it "should be [] if there are no values in the MODS" do
246
+ m = "<mods #{@ns_decl}><note>notit</note></mods>"
247
+ @smods_rec.from_str m
248
+ @smods_rec.sw_geographic_search.should == []
249
+ end
250
+ it "should not be empty Array if there are only subject/geographic elements" do
251
+ m = "<mods #{@ns_decl}><subject><geographic>#{@geo}</geographic></subject></mods>"
252
+ @smods_rec.from_str m
253
+ @smods_rec.sw_geographic_search.should == [@geo]
254
+ end
255
+ it "should not be empty Array if there are only subject/hierarchicalGeographic" do
256
+ m = "<mods #{@ns_decl}><subject><hierarchicalGeographic><country>#{@hier_geo_country}</country></hierarchicalGeographic></subject></mods>"
257
+ @smods_rec.from_str m
258
+ @smods_rec.sw_geographic_search.should == [@hier_geo_country]
259
+ end
260
+ it "should not be empty Array if there are only subject/geographicCode elements" do
261
+ m = "<mods #{@ns_decl}><subject><geographicCode authority='marcgac'>e-er</geographicCode></subject></mods>"
262
+ @smods_rec.from_str m
263
+ @smods_rec.sw_geographic_search.should == ['Estonia']
264
+ end
265
+ context "geographic subelement" do
266
+ it "should have a separate value for each geographic element" do
267
+ m = "<mods #{@ns_decl}>
268
+ <subject>
269
+ <geographic>Mississippi</geographic>
270
+ <geographic>Tippah County</geographic>
271
+ </subject>
272
+ <subject><geographic>Washington (D.C.)</geographic></subject>
273
+ </mods>"
274
+ @smods_rec.from_str m
275
+ @smods_rec.sw_geographic_search.should == ['Mississippi', 'Tippah County', 'Washington (D.C.)']
276
+ end
277
+ it "should be empty Array if there are only empty values in the MODS" do
278
+ m = "<mods #{@ns_decl}><subject><geographic/></subject><note>notit</note></mods>"
279
+ @smods_rec.from_str m
280
+ @smods_rec.sw_geographic_search.should == []
281
+ end
282
+ end
283
+ context "hierarchicalGeographic subelement" do
284
+ it "should have a separate value for each hierarchicalGeographic element" do
285
+ m = "<mods #{@ns_decl}>
286
+ <subject>
287
+ <hierarchicalGeographic><area>first</area></hierarchicalGeographic>
288
+ <hierarchicalGeographic><area>second</area></hierarchicalGeographic>
289
+ </subject>
290
+ <subject><hierarchicalGeographic><area>third</area></hierarchicalGeographic></subject>
291
+ </mods>"
292
+ @smods_rec.from_str m
293
+ @smods_rec.sw_geographic_search.should == ['first', 'second', 'third']
294
+ end
295
+ it "should be empty Array if there are only empty values in the MODS" do
296
+ m = "<mods #{@ns_decl}><subject><hierarchicalGeographic/></subject><note>notit</note></mods>"
297
+ @smods_rec.from_str m
298
+ @smods_rec.sw_geographic_search.should == []
299
+ end
300
+ context "combining subelements" do
301
+ before(:all) do
302
+ m = "<mods #{@ns_decl}>
303
+ <subject>
304
+ <hierarchicalGeographic>
305
+ <country>Canada</country>
306
+ <province>British Columbia</province>
307
+ <city>Vancouver</city>
308
+ </hierarchicalGeographic>
309
+ </subject></mods>"
310
+ @smods_rec.from_str m
311
+ end
312
+ it "uses a space as the separator by default" do
313
+ @smods_rec.sw_geographic_search.should == ['Canada British Columbia Vancouver']
314
+ end
315
+ it "honors any string value passed in for the separator" do
316
+ @smods_rec.sw_geographic_search(' --').should == ['Canada --British Columbia --Vancouver']
317
+ end
318
+ end
319
+ end # hierarchicalGeographic
320
+ context "geographicCode subelement" do
321
+ before(:all) do
322
+ m = "<mods #{@ns_decl}>
323
+ <subject><geographicCode authority='marcgac'>n-us-md</geographicCode></subject>
324
+ <subject><geographicCode authority='marcgac'>e-er</geographicCode></subject>
325
+ <subject><geographicCode authority='marccountry'>mg</geographicCode></subject>
326
+ <subject><geographicCode authority='iso3166'>us</geographicCode></subject>
327
+ </mods>"
328
+ @smods_rec.from_str m
329
+ @geo_search_from_codes = @smods_rec.sw_geographic_search
330
+ end
331
+ it "should not add untranslated values" do
332
+ @geo_search_from_codes.should_not include('n-us-md')
333
+ @geo_search_from_codes.should_not include('e-er')
334
+ @geo_search_from_codes.should_not include('mg')
335
+ @geo_search_from_codes.should_not include('us')
336
+ end
337
+ it "should translate marcgac codes" do
338
+ @geo_search_from_codes.should include('Estonia')
339
+ end
340
+ it "should translate marccountry codes" do
341
+ @geo_search_from_codes.should include('Madagascar')
342
+ end
343
+ it "should not translate other codes" do
344
+ @geo_search_from_codes.should_not include('United States')
345
+ end
346
+ it "should have a separate value for each geographicCode element" do
347
+ m = "<mods #{@ns_decl}>
348
+ <subject>
349
+ <geographicCode authority='marcgac'>e-er</geographicCode>
350
+ <geographicCode authority='marccountry'>mg</geographicCode>
351
+ </subject>
352
+ <subject><geographicCode authority='marcgac'>n-us-md</geographicCode></subject>
353
+ </mods>"
354
+ @smods_rec.from_str m
355
+ @smods_rec.sw_geographic_search.should == ['Estonia', 'Madagascar', 'Maryland']
356
+ end
357
+ it "should be empty Array if there are only empty values in the MODS" do
358
+ m = "<mods #{@ns_decl}><subject><geographicCode/></subject><note>notit</note></mods>"
359
+ @smods_rec.from_str m
360
+ @smods_rec.sw_geographic_search.should == []
361
+ end
362
+ it "should add the translated value if it wasn't present already" do
363
+ m = "<mods #{@ns_decl}>
364
+ <subject><geographic>Somewhere</geographic></subject>
365
+ <subject><geographicCode authority='marcgac'>e-er</geographicCode></subject>
366
+ </mods>"
367
+ @smods_rec.from_str m
368
+ @smods_rec.sw_geographic_search.size.should == 2
369
+ @smods_rec.sw_geographic_search.should include('Estonia')
370
+ end
371
+ it "should not add the translated value if it was already present" do
372
+ m = "<mods #{@ns_decl}>
373
+ <subject><geographic>Estonia</geographic></subject>
374
+ <subject><geographicCode authority='marcgac'>e-er</geographicCode></subject>
375
+ </mods>"
376
+ @smods_rec.from_str m
377
+ @smods_rec.sw_geographic_search.size.should == 1
378
+ @smods_rec.sw_geographic_search.should == ['Estonia']
379
+ end
380
+ end
381
+ end # sw_geographic_search
382
+ end # context sw subject methods
383
+
384
+ end