stanford-mods 0.0.27 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9617b16653a05aef7a4369146c3da872e27ae1fc
4
- data.tar.gz: e8b07e17af94b4cfc5e3210cd875c6a217efe86a
3
+ metadata.gz: f1bb292e526add1944d2595260b5edfdd66950fb
4
+ data.tar.gz: e814a340c6e3ceff0f0d5b373631409c3f5f0253
5
5
  SHA512:
6
- metadata.gz: ec62fd240d006e705d3767bb829c0ef15c18d9135b9acbab5838b4366d536c0e43de293bc53e4722b92cfb42b193c2b106ffdfbc103e3bbcd0802efd99bdfe1c
7
- data.tar.gz: 7588c07a0bf04c4cbceb8a291b833c54619529b8d94de5bcc1e6b3245a6daf288a1c5d4c1676684b39b6519e52ed08f1139713efeefa1df69f5869d93a36243b
6
+ metadata.gz: e9f4f142a9b09f8a61d82570b1fe0588dd3224645de7047e9b9229ff47c0efc15a12bba4583d0edce2ed2d36a2beddddb66edc3ea1edcc9010a6146136c8e1a5
7
+ data.tar.gz: b17d44c20f7bf39645f0659ddf034d6846c13ee6a548da2386b454269144882314acb34cfbde2d7a0baacd4e63f0d9d59aa9a859c4acf41f4cc651c15eb3ae18
data/README.rdoc CHANGED
@@ -59,6 +59,7 @@ Example Using SearchWorks Mixins:
59
59
  6. Create new Pull Request
60
60
 
61
61
  == Releases
62
+ * <b>1.0.0</b> sw_full_title now includes partName and partNumber; sw_title_display created to be like sw_full_title but without trailing punctuation; sw format for typeOfResource sound recording; genre value is librettos, plural; sw format algorithm accommodates first letter upcase; genre value report does NOT map to a format, genre value 'project report' with ToR text is 'Book'
62
63
  * <b>0.0.27</b> add genres 'Issue brief', 'Book chapter' and 'Working paper' to map to searchworks format 'Book'
63
64
  * <b>0.0.26</b> map typeOfResource 'sound recording-musical' to searchworks format 'Music - Recording' with spaces
64
65
  * <b>0.0.25</b> map typeOfResource 'text' and genre 'report' to searchworks format 'Book'
@@ -75,7 +75,7 @@ module Stanford
75
75
 
76
76
  # @return [Array<String>] values for author_corp_display
77
77
  def sw_corporate_authors
78
- val=@mods_ng_xml.plain_name.select {|n| n.type_at == 'corporate'}.map { |n| n.display_value_w_date }
78
+ val = @mods_ng_xml.plain_name.select {|n| n.type_at == 'corporate'}.map { |n| n.display_value_w_date }
79
79
  val
80
80
  end
81
81
 
@@ -123,13 +123,46 @@ module Stanford
123
123
  short_titles ? short_titles.first : nil
124
124
  end
125
125
 
126
- # @return [String] value for title_245_search, title_display, title_full_display
126
+ # @return [String] value for title_245_search, title_full_display
127
127
  def sw_full_title
128
- toret = full_titles ? full_titles.find { |s| s =~ Regexp.new(Regexp.escape(sw_short_title)) } : nil
129
- if toret
130
- toret = toret.gsub(/,$/, '')
128
+ outer_nodes = @mods_ng_xml.title_info
129
+ outer_node = outer_nodes ? outer_nodes.first : nil
130
+ if outer_node
131
+ nonSort = outer_node.nonSort.text.strip.empty? ? nil : outer_node.nonSort.text.strip
132
+ title = outer_node.title.text.strip.empty? ? nil: outer_node.title.text.strip
133
+ preSubTitle = nonSort ? [nonSort, title].compact.join(" ") : title
134
+ preSubTitle.sub!(/:$/, '') if preSubTitle # remove trailing colon
135
+
136
+ subTitle = outer_node.subTitle.text.strip
137
+ preParts = subTitle.empty? ? preSubTitle : preSubTitle + " : " + subTitle
138
+ preParts.sub!(/\.$/, '') if preParts # remove trailing period
139
+
140
+ partName = outer_node.partName.text.strip unless outer_node.partName.text.strip.empty?
141
+ partNumber = outer_node.partNumber.text.strip unless outer_node.partNumber.text.strip.empty?
142
+ partNumber.sub!(/,$/, '') if partNumber # remove trailing comma
143
+ if partNumber && partName
144
+ parts = partNumber + ", " + partName
145
+ elsif partNumber
146
+ parts = partNumber
147
+ elsif partName
148
+ parts = partName
149
+ end
150
+ parts.sub!(/\.$/, '') if parts
151
+
152
+ result = parts ? preParts + ". " + parts : preParts
153
+ result += "." if !result.match(/[[:punct:]]$/)
154
+ result = nil if result.empty?
155
+ result
156
+ else
157
+ nil
131
158
  end
132
- toret
159
+ end
160
+
161
+ # @return [String] value for title_display (like title_full_display without trailing punctuation)
162
+ def sw_title_display
163
+ result = sw_full_title ? sw_full_title : nil
164
+ result.sub!(/[[:punct:]]$/, '') if result
165
+ result
133
166
  end
134
167
 
135
168
  # this includes all titles except
@@ -141,17 +174,25 @@ module Stanford
141
174
  # Returns a sortable version of the main title
142
175
  # @return [String] value for title_sort field
143
176
  def sw_sort_title
144
- val = '' + ( sort_title ? sort_title : '')
145
- val.gsub(/[[:punct:]]*/, '').strip
177
+ # get nonSort piece
178
+ outer_nodes = @mods_ng_xml.title_info
179
+ outer_node = outer_nodes ? outer_nodes.first : nil
180
+ if outer_node
181
+ nonSort = outer_node.nonSort.text.strip.empty? ? nil : outer_node.nonSort.text.strip
182
+ end
183
+
184
+ val = '' + ( sw_full_title ? sw_full_title : '')
185
+ val.sub!(Regexp.new("^" + nonSort), '') if nonSort
186
+ val.gsub!(/[[:punct:]]*/, '').strip
187
+ val.squeeze(" ").strip
146
188
  end
147
189
 
148
190
  #remove trailing commas
191
+ # @deprecated in favor of sw_title_display
149
192
  def sw_full_title_without_commas
150
- toret = self.sw_full_title
151
- if toret
152
- toret = toret.gsub(/,$/, '')
153
- end
154
- toret
193
+ result = self.sw_full_title
194
+ result.sub!(/,$/, '') if result
195
+ result
155
196
  end
156
197
 
157
198
  # ---- end TITLE ----
@@ -501,23 +542,28 @@ module Stanford
501
542
  val << 'Computer File'
502
543
  when 'sound recording-musical'
503
544
  val << 'Music - Recording'
504
- when 'sound recording-nonmusical'
545
+ when 'sound recording-nonmusical', 'sound recording'
505
546
  val << 'Sound Recording'
506
547
  when 'still image'
507
548
  val << 'Image'
508
549
  when 'text'
509
550
  val << 'Book' if issuance and issuance.include? 'monographic'
510
- val << 'Book' if genres and genres.include? 'book chapter'
511
- val << 'Book' if genres and genres.include? 'issue brief'
512
- val << 'Book' if genres and genres.include? 'libretto'
513
- val << 'Book' if genres and genres.include? 'report'
514
- val << 'Book' if genres and genres.include? 'technical report'
515
- val << 'Book' if genres and genres.include? 'working paper'
516
- val << 'Conference Proceedings' if genres and genres.include? 'conference publication'
551
+ book_genres = ['book chapter', 'Book chapter', 'Book Chapter',
552
+ 'issue brief', 'Issue brief', 'Issue Brief',
553
+ 'librettos', 'Librettos',
554
+ 'project report', 'Project report', 'Project Report',
555
+ 'technical report', 'Technical report', 'Technical Report',
556
+ 'working paper', 'Working paper', 'Working Paper']
557
+ val << 'Book' if genres and !(genres & book_genres).empty?
558
+ conf_pub = ['conference publication', 'Conference publication', 'Conference Publication']
559
+ val << 'Conference Proceedings' if genres and !(genres & conf_pub).empty?
517
560
  val << 'Journal/Periodical' if issuance and issuance.include? 'continuing'
518
- val << 'Journal/Periodical' if genres and genres.include? 'article'
519
- val << 'Other' if genres and genres.include? 'student project report'
520
- val << 'Thesis' if genres and genres.include? 'thesis'
561
+ article = ['article', 'Article']
562
+ val << 'Journal/Periodical' if genres and !(genres & article).empty?
563
+ stu_proj_rpt = ['student project report', 'Student project report', 'Student Project report', 'Student Project Report']
564
+ val << 'Other' if genres and !(genres & stu_proj_rpt).empty?
565
+ thesis = ['thesis', 'Thesis']
566
+ val << 'Thesis' if genres and !(genres & thesis).empty?
521
567
  when 'three dimensional object'
522
568
  val << 'Other'
523
569
  end
@@ -1,6 +1,6 @@
1
1
  module Stanford
2
2
  module Mods
3
3
  # this is the Ruby Gem version
4
- VERSION = "0.0.27"
4
+ VERSION = "1.0.0"
5
5
  end
6
6
  end
@@ -13,38 +13,81 @@ describe "Format field from Searchworks mixin for Stanford::Mods::Record" do
13
13
  it 'originInfo/issuance monographic' do
14
14
  m = "<mods #{@ns_decl}><typeOfResource>text</typeOfResource><originInfo><issuance>monographic</issuance></originInfo></mods>"
15
15
  @smods_rec.from_str(m)
16
- @smods_rec.format.should == ['Book']
16
+ expect(@smods_rec.format).to eq ['Book']
17
17
  end
18
18
  context "genre" do
19
19
  it "'book chapter'", :email => 'mods-squad 2014-05-22, Joanna Dyla' do
20
20
  m = "<mods #{@ns_decl}><genre>book chapter</genre><typeOfResource>text</typeOfResource></mods>"
21
21
  @smods_rec.from_str(m)
22
- @smods_rec.format.should == ['Book']
22
+ expect(@smods_rec.format).to eq ['Book']
23
+ m = "<mods #{@ns_decl}><genre>Book chapter</genre><typeOfResource>text</typeOfResource></mods>"
24
+ @smods_rec.from_str(m)
25
+ expect(@smods_rec.format).to eq ['Book']
26
+ m = "<mods #{@ns_decl}><genre>Book Chapter</genre><typeOfResource>text</typeOfResource></mods>"
27
+ @smods_rec.from_str(m)
28
+ expect(@smods_rec.format).to eq ['Book']
23
29
  end
24
30
  it "'issue brief'", :email => 'mods-squad 2014-05-22, Joanna Dyla' do
25
31
  m = "<mods #{@ns_decl}><genre>issue brief</genre><typeOfResource>text</typeOfResource></mods>"
26
32
  @smods_rec.from_str(m)
27
- @smods_rec.format.should == ['Book']
33
+ expect(@smods_rec.format).to eq ['Book']
34
+ m = "<mods #{@ns_decl}><genre>Issue brief</genre><typeOfResource>text</typeOfResource></mods>"
35
+ @smods_rec.from_str(m)
36
+ expect(@smods_rec.format).to eq ['Book']
37
+ m = "<mods #{@ns_decl}><genre>Issue Brief</genre><typeOfResource>text</typeOfResource></mods>"
38
+ @smods_rec.from_str(m)
39
+ expect(@smods_rec.format).to eq ['Book']
28
40
  end
29
- it "'libretto'", :email => 'mods-squad 2014-05-22, Laura Wilsey' do
41
+ it "'librettos'", :jira => 'INDEX-98' do
42
+ m = "<mods #{@ns_decl}><genre>librettos</genre><typeOfResource>text</typeOfResource></mods>"
43
+ @smods_rec.from_str(m)
44
+ expect(@smods_rec.format).to eq ['Book']
45
+ m = "<mods #{@ns_decl}><genre>Librettos</genre><typeOfResource>text</typeOfResource></mods>"
46
+ @smods_rec.from_str(m)
47
+ expect(@smods_rec.format).to eq ['Book']
48
+ end
49
+ it "'libretto' isn't valid", :jira => 'INDEX-98' do
30
50
  m = "<mods #{@ns_decl}><genre>libretto</genre><typeOfResource>text</typeOfResource></mods>"
31
51
  @smods_rec.from_str(m)
32
- @smods_rec.format.should == ['Book']
52
+ expect(@smods_rec.format).to eq []
53
+ end
54
+ it "'project report'", :jira => 'GRYP-170', :github => 'gdor-indexer/#7' do
55
+ m = "<mods #{@ns_decl}><genre>project report</genre><typeOfResource>text</typeOfResource></mods>"
56
+ @smods_rec.from_str(m)
57
+ expect(@smods_rec.format).to eq ['Book']
58
+ m = "<mods #{@ns_decl}><genre>Project report</genre><typeOfResource>text</typeOfResource></mods>"
59
+ @smods_rec.from_str(m)
60
+ expect(@smods_rec.format).to eq ['Book']
61
+ m = "<mods #{@ns_decl}><genre>Project Report</genre><typeOfResource>text</typeOfResource></mods>"
62
+ @smods_rec.from_str(m)
63
+ expect(@smods_rec.format).to eq ['Book']
33
64
  end
34
- it "'report'", :jira => 'GRYP-170', :github => 'gdor-indexer/#7' do
65
+ it "'report' isn't valid", :jira => 'GRYP-170', :github => 'gdor-indexer/#7' do
35
66
  m = "<mods #{@ns_decl}><genre>report</genre><typeOfResource>text</typeOfResource></mods>"
36
67
  @smods_rec.from_str(m)
37
- @smods_rec.format.should == ['Book']
68
+ expect(@smods_rec.format).to eq []
38
69
  end
39
70
  it "'technical report'", :jira => 'GRYPHONDOR-207' do
40
71
  m = "<mods #{@ns_decl}><genre>technical report</genre><typeOfResource>text</typeOfResource></mods>"
41
72
  @smods_rec.from_str(m)
42
- @smods_rec.format.should == ['Book']
73
+ expect(@smods_rec.format).to eq ['Book']
74
+ m = "<mods #{@ns_decl}><genre>Technical report</genre><typeOfResource>text</typeOfResource></mods>"
75
+ @smods_rec.from_str(m)
76
+ expect(@smods_rec.format).to eq ['Book']
77
+ m = "<mods #{@ns_decl}><genre>Technical Report</genre><typeOfResource>text</typeOfResource></mods>"
78
+ @smods_rec.from_str(m)
79
+ expect(@smods_rec.format).to eq ['Book']
43
80
  end
44
81
  it "'working paper'", :email => 'mods-squad 2014-05-22, Joanna Dyla' do
45
82
  m = "<mods #{@ns_decl}><genre>working paper</genre><typeOfResource>text</typeOfResource></mods>"
46
83
  @smods_rec.from_str(m)
47
- @smods_rec.format.should == ['Book']
84
+ expect(@smods_rec.format).to eq ['Book']
85
+ m = "<mods #{@ns_decl}><genre>Working paper</genre><typeOfResource>text</typeOfResource></mods>"
86
+ @smods_rec.from_str(m)
87
+ expect(@smods_rec.format).to eq ['Book']
88
+ m = "<mods #{@ns_decl}><genre>Working Paper</genre><typeOfResource>text</typeOfResource></mods>"
89
+ @smods_rec.from_str(m)
90
+ expect(@smods_rec.format).to eq ['Book']
48
91
  end
49
92
  end
50
93
  end
@@ -54,67 +97,139 @@ describe "Format field from Searchworks mixin for Stanford::Mods::Record" do
54
97
  it "no genre (e.g. Dataset)" do
55
98
  m = "<mods #{@ns_decl}><typeOfResource>software, multimedia</typeOfResource></mods>"
56
99
  @smods_rec.from_str(m)
57
- @smods_rec.format.should == ['Computer File']
100
+ expect(@smods_rec.format).to eq ['Computer File']
58
101
  end
59
102
  it "genre 'game'", :jira => 'GRYPHONDOR-207' do
60
103
  m = "<mods #{@ns_decl}><genre>game</genre><typeOfResource>software, multimedia</typeOfResource></mods>"
61
104
  @smods_rec.from_str(m)
62
- @smods_rec.format.should == ['Computer File']
105
+ expect(@smods_rec.format).to eq ['Computer File']
106
+ m = "<mods #{@ns_decl}><genre>Game</genre><typeOfResource>software, multimedia</typeOfResource></mods>"
107
+ @smods_rec.from_str(m)
108
+ expect(@smods_rec.format).to eq ['Computer File']
63
109
  end
64
110
  end
65
111
 
66
112
  it "Conference Proceedings: typeOfResource 'text', genre 'conference publication'", :jira => 'GRYPHONDOR-207' do
67
113
  m = "<mods #{@ns_decl}><genre>conference publication</genre><typeOfResource>text</typeOfResource></mods>"
68
114
  @smods_rec.from_str(m)
69
- @smods_rec.format.should == ['Conference Proceedings']
115
+ expect(@smods_rec.format).to eq ['Conference Proceedings']
116
+ m = "<mods #{@ns_decl}><genre>Conference publication</genre><typeOfResource>text</typeOfResource></mods>"
117
+ @smods_rec.from_str(m)
118
+ expect(@smods_rec.format).to eq ['Conference Proceedings']
119
+ m = "<mods #{@ns_decl}><genre>Conference Publication</genre><typeOfResource>text</typeOfResource></mods>"
120
+ @smods_rec.from_str(m)
121
+ expect(@smods_rec.format).to eq ['Conference Proceedings']
70
122
  end
71
123
 
72
124
  it "Journal/Periodical: typeOfResource 'text', genre 'article'" do
73
125
  m = "<mods #{@ns_decl}><typeOfResource>text</typeOfResource><genre>article</genre></mods>"
74
126
  @smods_rec.from_str(m)
75
- @smods_rec.format.should == ['Journal/Periodical']
127
+ expect(@smods_rec.format).to eq ['Journal/Periodical']
128
+ m = "<mods #{@ns_decl}><typeOfResource>text</typeOfResource><genre>Article</genre></mods>"
129
+ @smods_rec.from_str(m)
130
+ expect(@smods_rec.format).to eq ['Journal/Periodical']
76
131
  end
77
132
 
78
133
  it "Image: typeOfResource 'still image'" do
79
134
  m = "<mods #{@ns_decl}><typeOfResource>still image</typeOfResource></mods>"
80
135
  @smods_rec.from_str(m)
81
- @smods_rec.format.should == ['Image']
136
+ expect(@smods_rec.format).to eq ['Image']
82
137
  end
83
138
 
84
139
  it "Music - Recording: typeOfResource 'sound recording-musical'", :jira => 'GRYPHONDOR-207' do
85
140
  m = "<mods #{@ns_decl}><typeOfResource>sound recording-musical</typeOfResource></mods>"
86
141
  @smods_rec.from_str(m)
87
- @smods_rec.format.should == ['Music - Recording']
142
+ expect(@smods_rec.format).to eq ['Music - Recording']
88
143
  end
89
144
 
90
145
  it "Music - Score: typeOfResource 'notated music'" do
91
146
  m = "<mods #{@ns_decl}><typeOfResource>notated music</typeOfResource></mods>"
92
147
  @smods_rec.from_str(m)
93
- @smods_rec.format.should == ['Music - Score']
148
+ expect(@smods_rec.format).to eq ['Music - Score']
94
149
  end
95
150
 
96
151
  it "Other: typeOfResource 'text', genre 'student project report'", :email => 'from Vitus, August 16, 2013' do
97
152
  m = "<mods #{@ns_decl}><genre>student project report</genre><typeOfResource>text</typeOfResource></mods>"
98
153
  @smods_rec.from_str(m)
99
- @smods_rec.format.should == ['Other']
154
+ expect(@smods_rec.format).to eq ['Other']
155
+ m = "<mods #{@ns_decl}><genre>Student project report</genre><typeOfResource>text</typeOfResource></mods>"
156
+ @smods_rec.from_str(m)
157
+ expect(@smods_rec.format).to eq ['Other']
158
+ m = "<mods #{@ns_decl}><genre>Student Project report</genre><typeOfResource>text</typeOfResource></mods>"
159
+ @smods_rec.from_str(m)
160
+ expect(@smods_rec.format).to eq ['Other']
161
+ m = "<mods #{@ns_decl}><genre>Student Project Report</genre><typeOfResource>text</typeOfResource></mods>"
162
+ @smods_rec.from_str(m)
163
+ expect(@smods_rec.format).to eq ['Other']
100
164
  end
101
165
 
102
- it "Sound Recording: typeOfResource 'sound recording-nonmusical', genre 'sound", :jira => 'GRYPHONDOR-207' do
103
- m = "<mods #{@ns_decl}><genre>sound</genre><typeOfResource>sound recording-nonmusical</typeOfResource></mods>"
166
+ context "Sound Recording:" do
167
+ it "typeOfResource 'sound recording-nonmusical', genre 'sound", :jira => 'GRYPHONDOR-207' do
168
+ m = "<mods #{@ns_decl}><genre>sound</genre><typeOfResource>sound recording-nonmusical</typeOfResource></mods>"
169
+ @smods_rec.from_str(m)
170
+ expect(@smods_rec.format).to eq ['Sound Recording']
171
+ m = "<mods #{@ns_decl}><genre>Sound</genre><typeOfResource>sound recording-nonmusical</typeOfResource></mods>"
172
+ @smods_rec.from_str(m)
173
+ expect(@smods_rec.format).to eq ['Sound Recording']
174
+ end
175
+ it "typeOfResource 'sound recording', genre 'sound", :jira => 'INDEX-94' do
176
+ m = "<mods #{@ns_decl}><genre>sound</genre><typeOfResource>sound recording</typeOfResource></mods>"
177
+ @smods_rec.from_str(m)
178
+ expect(@smods_rec.format).to eq ['Sound Recording']
179
+ m = "<mods #{@ns_decl}><genre>Sound</genre><typeOfResource>sound recording</typeOfResource></mods>"
180
+ @smods_rec.from_str(m)
181
+ expect(@smods_rec.format).to eq ['Sound Recording']
182
+ end
183
+ end
184
+
185
+ it "Thesis: typeOfResource 'text', genre 'thesis'" do
186
+ m = "<mods #{@ns_decl}><typeOfResource>text</typeOfResource><genre>thesis</genre></mods>"
187
+ @smods_rec.from_str(m)
188
+ expect(@smods_rec.format).to eq ['Thesis']
189
+ m = "<mods #{@ns_decl}><typeOfResource>text</typeOfResource><genre>Thesis</genre></mods>"
104
190
  @smods_rec.from_str(m)
105
- @smods_rec.format.should == ['Sound Recording']
191
+ expect(@smods_rec.format).to eq ['Thesis']
106
192
  end
107
193
 
108
194
  context "Video: typeOfResource 'moving image'" do
109
195
  it "no genre" do
110
196
  m = "<mods #{@ns_decl}><typeOfResource>moving image</typeOfResource></mods>"
111
197
  @smods_rec.from_str(m)
112
- @smods_rec.format.should == ['Video']
198
+ expect(@smods_rec.format).to eq ['Video']
113
199
  end
114
200
  it "genre 'motion picture'", :jira => 'GRYPHONDOR-207' do
115
201
  m = "<mods #{@ns_decl}><genre>motion picture</genre><typeOfResource>moving image</typeOfResource></mods>"
116
202
  @smods_rec.from_str(m)
117
- @smods_rec.format.should == ['Video']
203
+ expect(@smods_rec.format).to eq ['Video']
204
+ m = "<mods #{@ns_decl}><genre>Motion Picture</genre><typeOfResource>moving image</typeOfResource></mods>"
205
+ @smods_rec.from_str(m)
206
+ expect(@smods_rec.format).to eq ['Video']
207
+ m = "<mods #{@ns_decl}><genre>Motion Picture</genre><typeOfResource>moving image</typeOfResource></mods>"
208
+ @smods_rec.from_str(m)
209
+ expect(@smods_rec.format).to eq ['Video']
210
+ end
211
+ end
212
+
213
+ context "multiple format values", :jira => 'INDEX-32' do
214
+ it "multiple typeOfResource elements" do
215
+ m = "<mods #{@ns_decl}><typeOfResource>moving image</typeOfResource><typeOfResource>sound recording</typeOfResource></mods>"
216
+ @smods_rec.from_str(m)
217
+ expect(@smods_rec.format).to eq ['Video', 'Sound Recording']
218
+ end
219
+ it "multiple genre elements, single typeOfResource" do
220
+ m = "<mods #{@ns_decl}><typeOfResource>text</typeOfResource><genre>librettos</genre><genre>article</genre></mods>"
221
+ @smods_rec.from_str(m)
222
+ expect(@smods_rec.format).to eq ['Book', 'Journal/Periodical']
223
+ end
224
+ it "mish mash" do
225
+ m = "<mods #{@ns_decl}><typeOfResource>text</typeOfResource><typeOfResource>still image</typeOfResource><genre>librettos</genre><genre>article</genre></mods>"
226
+ @smods_rec.from_str(m)
227
+ expect(@smods_rec.format).to eq ['Book', 'Journal/Periodical', 'Image']
228
+ end
229
+ it "doesn't give duplicate values" do
230
+ m = "<mods #{@ns_decl}><typeOfResource>text</typeOfResource><genre>librettos</genre><genre>issue brief</genre></mods>"
231
+ @smods_rec.from_str(m)
232
+ expect(@smods_rec.format).to eq ['Book']
118
233
  end
119
234
  end
120
235
 
@@ -123,7 +238,7 @@ describe "Format field from Searchworks mixin for Stanford::Mods::Record" do
123
238
  <dateCreated>1904</dateCreated>
124
239
  </originInfo></mods>"
125
240
  @smods_rec.from_str(m)
126
- @smods_rec.format.should == []
241
+ expect(@smods_rec.format).to eq []
127
242
  end
128
243
 
129
244
  it "empty Array if weird typeOfResource value" do
@@ -131,6 +246,6 @@ describe "Format field from Searchworks mixin for Stanford::Mods::Record" do
131
246
  <typeOfResource>foo</typeOfResource>
132
247
  </originInfo></mods>"
133
248
  @smods_rec.from_str(m)
134
- @smods_rec.format.should == []
249
+ expect(@smods_rec.format).to eq []
135
250
  end
136
251
  end
@@ -178,8 +178,6 @@ describe "Date methods in Searchworks mixin for Stanford::Mods::Record" do
178
178
  end # u notation
179
179
 
180
180
 
181
-
182
-
183
181
  context 'pub_date_sort' do
184
182
  before :all do
185
183
  m = "<mods #{@ns_decl}><originInfo>
@@ -109,92 +109,5 @@ describe "Searchworks mixin for Stanford::Mods::Record" do
109
109
  end
110
110
  end
111
111
  end # context sw author methods
112
-
113
- context "sw title methods" do
114
- before(:all) do
115
- m = "<mods #{@ns_decl}><titleInfo><title>Jerk</title><subTitle>A Tale of Tourettes</subTitle><nonSort>The</nonSort></titleInfo></mods>"
116
- @smods_rec.from_str m
117
- end
118
-
119
- context "short title (for title_245a_search, title_245a_display) " do
120
- it "should call :short_titles" do
121
- @smods_rec.should_receive(:short_titles) # in Mods gem
122
- @smods_rec.sw_short_title
123
- end
124
- it "should be a String" do
125
- @smods_rec.sw_short_title.should == 'The Jerk'
126
- end
127
- end
128
-
129
- context "full title (for title_245_search, title_display, title_full_display)" do
130
- it "should call :full_titles" do
131
- @smods_rec.should_receive(:full_titles) # in Mods gem
132
- @smods_rec.sw_full_title
133
- end
134
- it "should be a String" do
135
- @smods_rec.sw_full_title.should == 'The Jerk A Tale of Tourettes'
136
- end
137
- it 'should escape regex characters in the sw_short_title' do
138
- m = "<mods #{@ns_decl}><titleInfo>
139
- <title>Pius V. Saint, [Michaele Gisleri),</title>
140
- </titleInfo></mods>"
141
- @smods_rec.from_str m
142
- @smods_rec.sw_full_title.should == 'Pius V. Saint, [Michaele Gisleri)'
143
- end
144
- end
145
-
146
- context "additional titles (for title_variant_search)" do
147
- before(:all) do
148
- m = "<mods #{@ns_decl}>
149
- <titleInfo type='alternative'><title>Alternative</title></titleInfo>
150
- <titleInfo><title>Jerk</title><nonSort>The</nonSort></titleInfo>
151
- <titleInfo><title>Joke</title></titleInfo>
152
- </mods>"
153
- @smods_rec.from_str(m)
154
- @addl_titles = @smods_rec.sw_addl_titles
155
- end
156
- it "should not include the main title" do
157
- @addl_titles.size.should == 2
158
- @addl_titles.should_not include(@smods_rec.sw_full_title)
159
- end
160
- it "should include any extra main titles" do
161
- @addl_titles.should include('Joke')
162
- end
163
- it "should include all alternative titles" do
164
- @addl_titles.should include('Alternative')
165
- end
166
- it 'shold escape the short title in the regexp' do
167
- m = "<mods #{@ns_decl}>
168
- <titleInfo type='alternative'><title>Alternative</title></titleInfo>
169
- <titleInfo><title>[Jerk)</title><nonSort>The</nonSort></titleInfo>
170
- <titleInfo><title>Joke]</title></titleInfo>
171
- </mods>"
172
- @smods_rec.from_str(m)
173
- @addl_titles = @smods_rec.sw_addl_titles
174
- end
175
- end
176
-
177
- context "sort title" do
178
- it "should be a String" do
179
- @smods_rec.sw_sort_title.should be_an_instance_of(String)
180
- end
181
- it "should use the sort title, as retrieved by :sort_title" do
182
- @smods_rec.should_receive(:sort_title) # in Mods gem
183
- @smods_rec.sw_sort_title
184
- end
185
- it "should not begin or end with whitespace" do
186
- m = "<mods #{@ns_decl}>
187
- <titleInfo><title> Jerk </title></titleInfo>
188
- </mods>"
189
- @smods_rec.from_str(m)
190
- @smods_rec.sw_sort_title.should == @smods_rec.sw_sort_title.strip
191
- end
192
- it "should not have any punctuation marks" do
193
- r = Stanford::Mods::Record.new
194
- r.from_str "<mods #{@ns_decl}><titleInfo><title>J,e.r;;;k</title></titleInfo></mods>"
195
- r.sw_sort_title.should =~ /^Jerk$/
196
- end
197
- end
198
- end # content sw title methods
199
112
 
200
113
  end
@@ -0,0 +1,578 @@
1
+ # encoding: UTF-8
2
+ require 'spec_helper'
3
+
4
+ describe "title fields from Searchworks mixin for Stanford::Mods::Record" do
5
+ before(:all) do
6
+ @smods_rec = Stanford::Mods::Record.new
7
+ @ns_decl = "xmlns='#{Mods::MODS_NS}'"
8
+ m = "<mods #{@ns_decl}><titleInfo><title>Jerk</title><subTitle>A Tale of Tourettes</subTitle><nonSort>The</nonSort></titleInfo></mods>"
9
+ @smods_rec.from_str m
10
+ end
11
+
12
+ context "short title (for title_245a_search, title_245a_display) " do
13
+ it "should call :short_titles" do
14
+ @smods_rec.should_receive(:short_titles) # in Mods gem
15
+ @smods_rec.sw_short_title
16
+ end
17
+ it "should be a String" do
18
+ expect(@smods_rec.sw_short_title).to eq 'The Jerk'
19
+ end
20
+ end
21
+
22
+ context "full title (for title_245_search, title_full_display)" do
23
+ it "should be a String" do
24
+ expect(@smods_rec.sw_full_title).to eq 'The Jerk : A Tale of Tourettes.'
25
+ end
26
+ it 'should cope with regex chars' do
27
+ m = "<mods #{@ns_decl}><titleInfo>
28
+ <title>Pius V. Saint, [Michaele Gisleri),</title>
29
+ </titleInfo></mods>"
30
+ @smods_rec.from_str m
31
+ expect(@smods_rec.sw_full_title).to eq 'Pius V. Saint, [Michaele Gisleri),'
32
+ end
33
+
34
+ context "punctuation" do
35
+ context "no subtitle" do
36
+ it "end title with a period" do
37
+ m = "<mods #{@ns_decl}>
38
+ <titleInfo>
39
+ <nonSort>The</nonSort>
40
+ <title>Olympics</title>
41
+ </titleInfo></mods>"
42
+ @smods_rec.from_str(m)
43
+ expect(@smods_rec.sw_full_title).to eq 'The Olympics.'
44
+ end
45
+ it "title already ends in period" do
46
+ m = "<mods #{@ns_decl}>
47
+ <titleInfo>
48
+ <nonSort>The</nonSort>
49
+ <title>Olympics.</title>
50
+ </titleInfo></mods>"
51
+ @smods_rec.from_str(m)
52
+ expect(@smods_rec.sw_full_title).to eq 'The Olympics.'
53
+ end
54
+ it "title already ends in other punctuation" do
55
+ m = "<mods #{@ns_decl}>
56
+ <titleInfo>
57
+ <nonSort>The</nonSort>
58
+ <title>Olympics!</title>
59
+ </titleInfo></mods>"
60
+ @smods_rec.from_str(m)
61
+ expect(@smods_rec.sw_full_title).to eq 'The Olympics!'
62
+ end
63
+ end # no subtitle
64
+ context "subtitle" do
65
+ it "end title with a colon" do
66
+ m = "<mods #{@ns_decl}>
67
+ <titleInfo>
68
+ <nonSort>The</nonSort>
69
+ <title>Olympics</title>
70
+ <subTitle>a history</subTitle>
71
+ </titleInfo></mods>"
72
+ @smods_rec.from_str(m)
73
+ expect(@smods_rec.sw_full_title).to eq 'The Olympics : a history.'
74
+ end
75
+ it "title already ends with colon" do
76
+ m = "<mods #{@ns_decl}>
77
+ <titleInfo>
78
+ <nonSort>The</nonSort>
79
+ <title>Olympics:</title>
80
+ <subTitle>a history</subTitle>
81
+ </titleInfo></mods>"
82
+ @smods_rec.from_str(m)
83
+ expect(@smods_rec.sw_full_title).to eq 'The Olympics : a history.'
84
+ end #
85
+ # "end subtitle with period" - see above
86
+ it "subtitle already ends with period" do
87
+ m = "<mods #{@ns_decl}>
88
+ <titleInfo>
89
+ <nonSort>The</nonSort>
90
+ <title>Olympics</title>
91
+ <subTitle>a history.</subTitle>
92
+ </titleInfo></mods>"
93
+ @smods_rec.from_str(m)
94
+ expect(@smods_rec.sw_full_title).to eq 'The Olympics : a history.'
95
+ end
96
+ it "subtitle already ends with other punctuation" do
97
+ m = "<mods #{@ns_decl}>
98
+ <titleInfo>
99
+ <nonSort>The</nonSort>
100
+ <title>Olympics</title>
101
+ <subTitle>a history?</subTitle>
102
+ </titleInfo></mods>"
103
+ @smods_rec.from_str(m)
104
+ expect(@smods_rec.sw_full_title).to eq 'The Olympics : a history?'
105
+ end
106
+ end # subtitle
107
+ context "partName" do
108
+ context "no partNumber" do
109
+ it "end partName with period" do
110
+ m = "<mods #{@ns_decl}>
111
+ <titleInfo>
112
+ <nonSort>The</nonSort>
113
+ <title>Olympics</title>
114
+ <subTitle>a history</subTitle>
115
+ <partName>Ancient</partName>
116
+ </titleInfo></mods>"
117
+ @smods_rec.from_str(m)
118
+ expect(@smods_rec.sw_full_title).to eq 'The Olympics : a history. Ancient.'
119
+ m = "<mods #{@ns_decl}>
120
+ <titleInfo>
121
+ <title>cfb</title>
122
+ <partName>Appendix</partName>
123
+ </titleInfo></mods>"
124
+ @smods_rec.from_str(m)
125
+ expect(@smods_rec.sw_full_title).to eq 'cfb. Appendix.'
126
+ end
127
+ it "partName already ends with period" do
128
+ m = "<mods #{@ns_decl}>
129
+ <titleInfo>
130
+ <nonSort>The</nonSort>
131
+ <title>Olympics</title>
132
+ <subTitle>a history</subTitle>
133
+ <partName>Ancient.</partName>
134
+ </titleInfo></mods>"
135
+ @smods_rec.from_str(m)
136
+ expect(@smods_rec.sw_full_title).to eq 'The Olympics : a history. Ancient.'
137
+ m = "<mods #{@ns_decl}>
138
+ <titleInfo>
139
+ <title>cfb</title>
140
+ <partName>Appendix.</partName>
141
+ </titleInfo></mods>"
142
+ @smods_rec.from_str(m)
143
+ expect(@smods_rec.sw_full_title).to eq 'cfb. Appendix.'
144
+ end
145
+ end # no partNumber
146
+ context "partNumber" do
147
+ it "end partNumber with comma" do
148
+ m = "<mods #{@ns_decl}>
149
+ <titleInfo>
150
+ <nonSort>The</nonSort>
151
+ <title>Olympics</title>
152
+ <subTitle>a history</subTitle>
153
+ <partNumber>Part 1</partNumber>
154
+ <partName>Ancient</partName>
155
+ </titleInfo></mods>"
156
+ @smods_rec.from_str(m)
157
+ expect(@smods_rec.sw_full_title).to eq 'The Olympics : a history. Part 1, Ancient.'
158
+ m = "<mods #{@ns_decl}>
159
+ <titleInfo>
160
+ <title>cfb</title>
161
+ <partNumber>1894</partNumber>
162
+ <partName>Appendix</partName>
163
+ </titleInfo></mods>"
164
+ @smods_rec.from_str(m)
165
+ expect(@smods_rec.sw_full_title).to eq 'cfb. 1894, Appendix.'
166
+ end
167
+ it "partNumber already ends with comma" do
168
+ m = "<mods #{@ns_decl}>
169
+ <titleInfo>
170
+ <nonSort>The</nonSort>
171
+ <title>Olympics</title>
172
+ <subTitle>a history</subTitle>
173
+ <partNumber>Part 1,</partNumber>
174
+ <partName>Ancient</partName>
175
+ </titleInfo></mods>"
176
+ @smods_rec.from_str(m)
177
+ expect(@smods_rec.sw_full_title).to eq 'The Olympics : a history. Part 1, Ancient.'
178
+ m = "<mods #{@ns_decl}>
179
+ <titleInfo>
180
+ <title>cfb</title>
181
+ <partNumber>1894,</partNumber>
182
+ <partName>Appendix</partName>
183
+ </titleInfo></mods>"
184
+ @smods_rec.from_str(m)
185
+ expect(@smods_rec.sw_full_title).to eq 'cfb. 1894, Appendix.'
186
+ end
187
+ end
188
+ end # partName
189
+ context "no partName, but partNumber" do
190
+ it "end partNumber with period" do
191
+ m = "<mods #{@ns_decl}>
192
+ <titleInfo>
193
+ <nonSort>The</nonSort>
194
+ <title>Olympics</title>
195
+ <subTitle>a history</subTitle>
196
+ <partNumber>Part 1</partNumber>
197
+ </titleInfo></mods>"
198
+ @smods_rec.from_str(m)
199
+ expect(@smods_rec.sw_full_title).to eq 'The Olympics : a history. Part 1.'
200
+ m = "<mods #{@ns_decl}>
201
+ <titleInfo>
202
+ <title>cfb</title>
203
+ <partNumber>1894</partNumber>
204
+ </titleInfo></mods>"
205
+ @smods_rec.from_str(m)
206
+ expect(@smods_rec.sw_full_title).to eq 'cfb. 1894.'
207
+ end
208
+ it "parNumber already ends in period" do
209
+ m = "<mods #{@ns_decl}>
210
+ <titleInfo>
211
+ <nonSort>The</nonSort>
212
+ <title>Olympics</title>
213
+ <subTitle>a history</subTitle>
214
+ <partNumber>Part 1.</partNumber>
215
+ </titleInfo></mods>"
216
+ @smods_rec.from_str(m)
217
+ expect(@smods_rec.sw_full_title).to eq 'The Olympics : a history. Part 1.'
218
+ m = "<mods #{@ns_decl}>
219
+ <titleInfo>
220
+ <title>cfb</title>
221
+ <partNumber>1894.</partNumber>
222
+ </titleInfo></mods>"
223
+ @smods_rec.from_str(m)
224
+ expect(@smods_rec.sw_full_title).to eq 'cfb. 1894.'
225
+ end
226
+ it "partNumber already ends with other punctuation" do
227
+ m = "<mods #{@ns_decl}>
228
+ <titleInfo>
229
+ <nonSort>The</nonSort>
230
+ <title>Olympics</title>
231
+ <subTitle>a history</subTitle>
232
+ <partNumber>Part 1!</partNumber>
233
+ </titleInfo></mods>"
234
+ @smods_rec.from_str(m)
235
+ expect(@smods_rec.sw_full_title).to eq 'The Olympics : a history. Part 1!'
236
+ m = "<mods #{@ns_decl}>
237
+ <titleInfo>
238
+ <title>cfb</title>
239
+ <partNumber>1894?</partNumber>
240
+ </titleInfo></mods>"
241
+ @smods_rec.from_str(m)
242
+ expect(@smods_rec.sw_full_title).to eq 'cfb. 1894?'
243
+ end
244
+ end # no partName but partNumber
245
+ end # punctuation
246
+ end # sw_full_title
247
+
248
+ context "sw_title_display removes end punctuation of sw_full_title_display" do
249
+ context "no subtitle" do
250
+ it "end title with a period" do
251
+ m = "<mods #{@ns_decl}>
252
+ <titleInfo>
253
+ <nonSort>The</nonSort>
254
+ <title>Olympics</title>
255
+ </titleInfo></mods>"
256
+ @smods_rec.from_str(m)
257
+ expect(@smods_rec.sw_title_display).to eq 'The Olympics'
258
+ end
259
+ it "title already ends in period" do
260
+ m = "<mods #{@ns_decl}>
261
+ <titleInfo>
262
+ <nonSort>The</nonSort>
263
+ <title>Olympics.</title>
264
+ </titleInfo></mods>"
265
+ @smods_rec.from_str(m)
266
+ expect(@smods_rec.sw_title_display).to eq 'The Olympics'
267
+ end
268
+ it "title already ends in other punctuation" do
269
+ m = "<mods #{@ns_decl}>
270
+ <titleInfo>
271
+ <nonSort>The</nonSort>
272
+ <title>Olympics!</title>
273
+ </titleInfo></mods>"
274
+ @smods_rec.from_str(m)
275
+ expect(@smods_rec.sw_title_display).to eq 'The Olympics'
276
+ end
277
+ end # no subtitle
278
+ context "subtitle" do
279
+ it "end title with a colon" do
280
+ m = "<mods #{@ns_decl}>
281
+ <titleInfo>
282
+ <nonSort>The</nonSort>
283
+ <title>Olympics</title>
284
+ <subTitle>a history</subTitle>
285
+ </titleInfo></mods>"
286
+ @smods_rec.from_str(m)
287
+ expect(@smods_rec.sw_title_display).to eq 'The Olympics : a history'
288
+ end
289
+ it "title already ends with colon" do
290
+ m = "<mods #{@ns_decl}>
291
+ <titleInfo>
292
+ <nonSort>The</nonSort>
293
+ <title>Olympics:</title>
294
+ <subTitle>a history</subTitle>
295
+ </titleInfo></mods>"
296
+ @smods_rec.from_str(m)
297
+ expect(@smods_rec.sw_title_display).to eq 'The Olympics : a history'
298
+ end #
299
+ # "end subtitle with period" - see above
300
+ it "subtitle already ends with period" do
301
+ m = "<mods #{@ns_decl}>
302
+ <titleInfo>
303
+ <nonSort>The</nonSort>
304
+ <title>Olympics</title>
305
+ <subTitle>a history.</subTitle>
306
+ </titleInfo></mods>"
307
+ @smods_rec.from_str(m)
308
+ expect(@smods_rec.sw_title_display).to eq 'The Olympics : a history'
309
+ end
310
+ it "subtitle already ends with other punctuation" do
311
+ m = "<mods #{@ns_decl}>
312
+ <titleInfo>
313
+ <nonSort>The</nonSort>
314
+ <title>Olympics</title>
315
+ <subTitle>a history?</subTitle>
316
+ </titleInfo></mods>"
317
+ @smods_rec.from_str(m)
318
+ expect(@smods_rec.sw_title_display).to eq 'The Olympics : a history'
319
+ end
320
+ end # subtitle
321
+ context "partName" do
322
+ context "no partNumber" do
323
+ it "end partName with period" do
324
+ m = "<mods #{@ns_decl}>
325
+ <titleInfo>
326
+ <nonSort>The</nonSort>
327
+ <title>Olympics</title>
328
+ <subTitle>a history</subTitle>
329
+ <partName>Ancient</partName>
330
+ </titleInfo></mods>"
331
+ @smods_rec.from_str(m)
332
+ expect(@smods_rec.sw_title_display).to eq 'The Olympics : a history. Ancient'
333
+ m = "<mods #{@ns_decl}>
334
+ <titleInfo>
335
+ <title>cfb</title>
336
+ <partName>Appendix</partName>
337
+ </titleInfo></mods>"
338
+ @smods_rec.from_str(m)
339
+ expect(@smods_rec.sw_title_display).to eq 'cfb. Appendix'
340
+ end
341
+ it "partName already ends with period" do
342
+ m = "<mods #{@ns_decl}>
343
+ <titleInfo>
344
+ <nonSort>The</nonSort>
345
+ <title>Olympics</title>
346
+ <subTitle>a history</subTitle>
347
+ <partName>Ancient.</partName>
348
+ </titleInfo></mods>"
349
+ @smods_rec.from_str(m)
350
+ expect(@smods_rec.sw_title_display).to eq 'The Olympics : a history. Ancient'
351
+ m = "<mods #{@ns_decl}>
352
+ <titleInfo>
353
+ <title>cfb</title>
354
+ <partName>Appendix.</partName>
355
+ </titleInfo></mods>"
356
+ @smods_rec.from_str(m)
357
+ expect(@smods_rec.sw_title_display).to eq 'cfb. Appendix'
358
+ end
359
+ end # no partNumber
360
+ context "partNumber" do
361
+ it "end partNumber with comma" do
362
+ m = "<mods #{@ns_decl}>
363
+ <titleInfo>
364
+ <nonSort>The</nonSort>
365
+ <title>Olympics</title>
366
+ <subTitle>a history</subTitle>
367
+ <partNumber>Part 1</partNumber>
368
+ <partName>Ancient</partName>
369
+ </titleInfo></mods>"
370
+ @smods_rec.from_str(m)
371
+ expect(@smods_rec.sw_title_display).to eq 'The Olympics : a history. Part 1, Ancient'
372
+ m = "<mods #{@ns_decl}>
373
+ <titleInfo>
374
+ <title>cfb</title>
375
+ <partNumber>1894</partNumber>
376
+ <partName>Appendix</partName>
377
+ </titleInfo></mods>"
378
+ @smods_rec.from_str(m)
379
+ expect(@smods_rec.sw_title_display).to eq 'cfb. 1894, Appendix'
380
+ end
381
+ it "partNumber already ends with comma" do
382
+ m = "<mods #{@ns_decl}>
383
+ <titleInfo>
384
+ <nonSort>The</nonSort>
385
+ <title>Olympics</title>
386
+ <subTitle>a history</subTitle>
387
+ <partNumber>Part 1,</partNumber>
388
+ <partName>Ancient</partName>
389
+ </titleInfo></mods>"
390
+ @smods_rec.from_str(m)
391
+ expect(@smods_rec.sw_title_display).to eq 'The Olympics : a history. Part 1, Ancient'
392
+ m = "<mods #{@ns_decl}>
393
+ <titleInfo>
394
+ <title>cfb</title>
395
+ <partNumber>1894,</partNumber>
396
+ <partName>Appendix</partName>
397
+ </titleInfo></mods>"
398
+ @smods_rec.from_str(m)
399
+ expect(@smods_rec.sw_title_display).to eq 'cfb. 1894, Appendix'
400
+ end
401
+ end
402
+ end # partName
403
+ context "no partName, but partNumber" do
404
+ it "end partNumber with period" do
405
+ m = "<mods #{@ns_decl}>
406
+ <titleInfo>
407
+ <nonSort>The</nonSort>
408
+ <title>Olympics</title>
409
+ <subTitle>a history</subTitle>
410
+ <partNumber>Part 1</partNumber>
411
+ </titleInfo></mods>"
412
+ @smods_rec.from_str(m)
413
+ expect(@smods_rec.sw_title_display).to eq 'The Olympics : a history. Part 1'
414
+ m = "<mods #{@ns_decl}>
415
+ <titleInfo>
416
+ <title>cfb</title>
417
+ <partNumber>1894</partNumber>
418
+ </titleInfo></mods>"
419
+ @smods_rec.from_str(m)
420
+ expect(@smods_rec.sw_title_display).to eq 'cfb. 1894'
421
+ end
422
+ it "parNumber already ends in period" do
423
+ m = "<mods #{@ns_decl}>
424
+ <titleInfo>
425
+ <nonSort>The</nonSort>
426
+ <title>Olympics</title>
427
+ <subTitle>a history</subTitle>
428
+ <partNumber>Part 1.</partNumber>
429
+ </titleInfo></mods>"
430
+ @smods_rec.from_str(m)
431
+ expect(@smods_rec.sw_title_display).to eq 'The Olympics : a history. Part 1'
432
+ m = "<mods #{@ns_decl}>
433
+ <titleInfo>
434
+ <title>cfb</title>
435
+ <partNumber>1894.</partNumber>
436
+ </titleInfo></mods>"
437
+ @smods_rec.from_str(m)
438
+ expect(@smods_rec.sw_title_display).to eq 'cfb. 1894'
439
+ end
440
+ it "partNumber already ends with other punctuation" do
441
+ m = "<mods #{@ns_decl}>
442
+ <titleInfo>
443
+ <nonSort>The</nonSort>
444
+ <title>Olympics</title>
445
+ <subTitle>a history</subTitle>
446
+ <partNumber>Part 1!</partNumber>
447
+ </titleInfo></mods>"
448
+ @smods_rec.from_str(m)
449
+ expect(@smods_rec.sw_title_display).to eq 'The Olympics : a history. Part 1'
450
+ m = "<mods #{@ns_decl}>
451
+ <titleInfo>
452
+ <title>cfb</title>
453
+ <partNumber>1894?</partNumber>
454
+ </titleInfo></mods>"
455
+ @smods_rec.from_str(m)
456
+ expect(@smods_rec.sw_title_display).to eq 'cfb. 1894'
457
+ end
458
+ end # no partName but partNumber
459
+ end # sw_title_display
460
+
461
+ context "additional titles (for title_variant_search)" do
462
+ before(:all) do
463
+ m = "<mods #{@ns_decl}>
464
+ <titleInfo type='alternative'><title>Alternative</title></titleInfo>
465
+ <titleInfo><title>Jerk</title><nonSort>The</nonSort></titleInfo>
466
+ <titleInfo><title>Joke</title></titleInfo>
467
+ </mods>"
468
+ @smods_rec.from_str(m)
469
+ @addl_titles = @smods_rec.sw_addl_titles
470
+ end
471
+ it "should not include the main title" do
472
+ expect(@addl_titles.size).to eq 2
473
+ expect(@addl_titles).not_to include(@smods_rec.sw_full_title)
474
+ end
475
+ it "should include any extra main titles" do
476
+ expect(@addl_titles).to include('Joke')
477
+ end
478
+ it "should include all alternative titles" do
479
+ expect(@addl_titles).to include('Alternative')
480
+ end
481
+ it 'should cope with regexp chars in the short title when determining addl titles' do
482
+ m = "<mods #{@ns_decl}>
483
+ <titleInfo type='alternative'><title>Alternative</title></titleInfo>
484
+ <titleInfo><title>[Jerk)</title><nonSort>The</nonSort></titleInfo>
485
+ <titleInfo><title>Joke]</title></titleInfo>
486
+ </mods>"
487
+ @smods_rec.from_str(m)
488
+ expect(@smods_rec.sw_addl_titles).to eq ['Alternative', 'Joke]']
489
+ end
490
+ end
491
+
492
+ context "sort title" do
493
+ it "should be a String" do
494
+ expect(@smods_rec.sw_sort_title).to be_an_instance_of(String)
495
+ end
496
+ it "should use the sw_full_title as a starting point" do
497
+ @smods_rec.should_receive(:sw_full_title)
498
+ @smods_rec.sw_sort_title
499
+ end
500
+ it "should not begin or end with whitespace" do
501
+ m = "<mods #{@ns_decl}>
502
+ <titleInfo><title> Jerk </title></titleInfo>
503
+ </mods>"
504
+ @smods_rec.from_str(m)
505
+ expect(@smods_rec.sw_sort_title).to eq @smods_rec.sw_sort_title.strip
506
+ end
507
+ it "should not have any punctuation marks" do
508
+ r = Stanford::Mods::Record.new
509
+ r.from_str "<mods #{@ns_decl}><titleInfo><title>J,e.r;;;k</title></titleInfo></mods>"
510
+ expect(r.sw_sort_title).to match /^Jerk$/
511
+ end
512
+ end
513
+
514
+ context "part number should be in full title and sort title", :jira => ['INDEX-31', 'GRYPHONDOR-372'] do
515
+ before(:all) do
516
+ @mccarthy_smods_rec = Stanford::Mods::Record.new
517
+ mccarthy = "<mods #{@ns_decl}>
518
+ <titleInfo>
519
+ <title>McCarthy, John</title>
520
+ <partNumber>Part 2</partNumber>
521
+ </titleInfo></mods>"
522
+ @mccarthy_smods_rec.from_str(mccarthy)
523
+ @insp_general_smods_rec = Stanford::Mods::Record.new
524
+ insp_general = "<mods #{@ns_decl}>
525
+ <titleInfo>
526
+ <title>Semiannual report to Congress</title>
527
+ <partNumber>October 1, 1998 - March 31, 1999</partNumber>
528
+ </titleInfo>
529
+ <titleInfo type=\"uniform\">
530
+ <title>Semiannual report to Congress (Online)</title>
531
+ </titleInfo></mods>"
532
+ @insp_general_smods_rec.from_str(insp_general)
533
+ @cfb_smods_rec = Stanford::Mods::Record.new
534
+ cfb = "<mods #{@ns_decl}>
535
+ <titleInfo>
536
+ <title>cfb</title>
537
+ <partNumber>1894</partNumber>
538
+ <partName>Appendix</partName>
539
+ </titleInfo></mods>"
540
+ @cfb_smods_rec.from_str(cfb)
541
+ @all_smods_rec = Stanford::Mods::Record.new
542
+ all = "<mods #{@ns_decl}>
543
+ <titleInfo>
544
+ <nonSort>The</nonSort>
545
+ <title>Olympics</title>
546
+ <subTitle>a history</subTitle>
547
+ <partNumber>Part 1</partNumber>
548
+ <partName>Ancient</partName>
549
+ </titleInfo></mods>"
550
+ @all_smods_rec.from_str(all)
551
+ end
552
+ it "short titles" do
553
+ expect(@mccarthy_smods_rec.sw_short_title).to eql 'McCarthy, John'
554
+ expect(@insp_general_smods_rec.sw_short_title).to eql 'Semiannual report to Congress'
555
+ expect(@cfb_smods_rec.sw_short_title).to eql 'cfb'
556
+ expect(@all_smods_rec.sw_short_title).to eql 'The Olympics'
557
+ end
558
+ it "full titles" do
559
+ expect(@mccarthy_smods_rec.sw_full_title).to eql 'McCarthy, John. Part 2.'
560
+ expect(@insp_general_smods_rec.sw_full_title).to eql 'Semiannual report to Congress. October 1, 1998 - March 31, 1999.'
561
+ expect(@cfb_smods_rec.sw_full_title).to eql 'cfb. 1894, Appendix.'
562
+ expect(@all_smods_rec.sw_full_title).to eql 'The Olympics : a history. Part 1, Ancient.'
563
+ end
564
+ it "additional titles" do
565
+ expect(@mccarthy_smods_rec.sw_addl_titles).to eql []
566
+ expect(@insp_general_smods_rec.sw_addl_titles).to eql []
567
+ expect(@cfb_smods_rec.sw_addl_titles).to eql []
568
+ expect(@all_smods_rec.sw_addl_titles).to eql []
569
+ end
570
+ it "sort title" do
571
+ expect(@mccarthy_smods_rec.sw_sort_title).to eql 'McCarthy John Part 2'
572
+ expect(@insp_general_smods_rec.sw_sort_title).to eql 'Semiannual report to Congress October 1 1998 March 31 1999'
573
+ expect(@cfb_smods_rec.sw_sort_title).to eql 'cfb 1894 Appendix'
574
+ expect(@all_smods_rec.sw_sort_title).to eql 'Olympics a history Part 1 Ancient'
575
+ end
576
+ end
577
+
578
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stanford-mods
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.27
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Naomi Dushay
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-05-27 00:00:00.000000000 Z
12
+ date: 2014-06-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: mods
@@ -111,6 +111,7 @@ files:
111
111
  - spec/searchworks_spec.rb
112
112
  - spec/searchworks_subject_raw_spec.rb
113
113
  - spec/searchworks_subject_spec.rb
114
+ - spec/searchworks_title_spec.rb
114
115
  - spec/spec_helper.rb
115
116
  - stanford-mods.gemspec
116
117
  homepage: https://github.com/sul-dlss/stanford-mods
@@ -143,5 +144,6 @@ test_files:
143
144
  - spec/searchworks_spec.rb
144
145
  - spec/searchworks_subject_raw_spec.rb
145
146
  - spec/searchworks_subject_spec.rb
147
+ - spec/searchworks_title_spec.rb
146
148
  - spec/spec_helper.rb
147
149
  has_rdoc: