stanford-mods 2.2.0 → 2.2.1

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.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.rubocop_todo.yml +358 -3
  4. data/.travis.yml +1 -4
  5. data/Gemfile +3 -4
  6. data/Rakefile +3 -3
  7. data/lib/marc_countries.rb +381 -381
  8. data/lib/stanford-mods.rb +1 -0
  9. data/lib/stanford-mods/coordinate.rb +14 -36
  10. data/lib/stanford-mods/date_parsing.rb +7 -8
  11. data/lib/stanford-mods/geo_spatial.rb +32 -12
  12. data/lib/stanford-mods/geo_utils.rb +28 -0
  13. data/lib/stanford-mods/imprint.rb +1 -1
  14. data/lib/stanford-mods/name.rb +7 -15
  15. data/lib/stanford-mods/origin_info.rb +35 -37
  16. data/lib/stanford-mods/physical_location.rb +6 -4
  17. data/lib/stanford-mods/searchworks.rb +149 -182
  18. data/lib/stanford-mods/searchworks_languages.rb +3 -3
  19. data/lib/stanford-mods/searchworks_subjects.rb +16 -18
  20. data/lib/stanford-mods/version.rb +1 -1
  21. data/spec/date_parsing_spec.rb +17 -19
  22. data/spec/fixtures/searchworks_imprint_data.rb +1 -1
  23. data/spec/fixtures/searchworks_pub_date_data.rb +1 -1
  24. data/spec/fixtures/spotlight_pub_date_data.rb +1 -1
  25. data/spec/geo_spatial_spec.rb +51 -5
  26. data/spec/imprint_spec.rb +4 -6
  27. data/spec/lib/stanford-mods/coordinate_spec.rb +0 -2
  28. data/spec/name_spec.rb +0 -2
  29. data/spec/origin_info_spec.rb +26 -28
  30. data/spec/physical_location_spec.rb +0 -3
  31. data/spec/searchworks_basic_spec.rb +1 -2
  32. data/spec/searchworks_format_spec.rb +35 -39
  33. data/spec/searchworks_pub_dates_spec.rb +0 -5
  34. data/spec/searchworks_spec.rb +1 -7
  35. data/spec/searchworks_subject_raw_spec.rb +0 -5
  36. data/spec/searchworks_subject_spec.rb +2 -9
  37. data/spec/searchworks_title_spec.rb +0 -2
  38. data/spec/spec_helper.rb +2 -5
  39. data/spec/sw_publication_spec.rb +1 -2
  40. data/stanford-mods.gemspec +1 -2
  41. metadata +4 -4
@@ -484,7 +484,7 @@ SEARCHWORKS_LANGUAGES = {
484
484
  'uig' => 'Uighur',
485
485
  'ukr' => 'Ukrainian',
486
486
  'umb' => 'Umbundu',
487
- #'und' => 'Undetermined',
487
+ # 'und' => 'Undetermined',
488
488
  'urd' => 'Urdu',
489
489
  'uzb' => 'Uzbek',
490
490
  'vai' => 'Vai',
@@ -514,6 +514,6 @@ SEARCHWORKS_LANGUAGES = {
514
514
  'znd' => 'Zande',
515
515
  'zul' => 'Zulu',
516
516
  'zun' => 'Zuni',
517
- #'zxx' => 'null',
517
+ # 'zxx' => 'null',
518
518
  'zza' => 'Zaza'
519
- }
519
+ }.freeze
@@ -6,7 +6,6 @@ require 'mods'
6
6
  module Stanford
7
7
  module Mods
8
8
  class Record < ::Mods::Record
9
-
10
9
  # Values are the contents of:
11
10
  # subject/geographic
12
11
  # subject/hierarchicalGeographic
@@ -28,7 +27,7 @@ module Stanford
28
27
  trans_code_vals = @mods_ng_xml.subject.geographicCode.translated_value
29
28
  if trans_code_vals
30
29
  trans_code_vals.each { |val|
31
- result << val if !result.include?(val)
30
+ result << val unless result.include?(val)
32
31
  }
33
32
  end
34
33
 
@@ -68,7 +67,7 @@ module Stanford
68
67
  # @return [Array<String>] values for the topic_search Solr field for this document or nil if none
69
68
  def topic_search
70
69
  @topic_search ||= begin
71
- vals = self.term_values(:genre) || []
70
+ vals = term_values(:genre) || []
72
71
  vals.concat(subject_topics) if subject_topics
73
72
  vals.empty? ? nil : vals
74
73
  end
@@ -96,13 +95,13 @@ module Stanford
96
95
  # geographic_search values with trailing comma, semicolon, and backslash (and any preceding spaces) removed
97
96
  # @return [Array<String>] values for the geographic_facet Solr field for this document or nil if none
98
97
  def geographic_facet
99
- geographic_search.map { |val| val.sub(/[\\,;]$/, '').strip } unless !geographic_search
98
+ geographic_search.map { |val| val.sub(/[\\,;]$/, '').strip } if geographic_search
100
99
  end
101
100
 
102
101
  # subject/temporal values with trailing comma, semicolon, and backslash (and any preceding spaces) removed
103
102
  # @return [Array<String>] values for the era_facet Solr field for this document or nil if none
104
103
  def era_facet
105
- subject_temporal.map { |val| val.sub(/[\\,;]$/, '').strip } unless !subject_temporal
104
+ subject_temporal.map { |val| val.sub(/[\\,;]$/, '').strip } if subject_temporal
106
105
  end
107
106
 
108
107
  # Values are the contents of:
@@ -112,14 +111,14 @@ module Stanford
112
111
  # @return [Array<String>] values for the geographic_search Solr field for this document or nil if none
113
112
  def geographic_search
114
113
  @geographic_search ||= begin
115
- result = self.sw_geographic_search
114
+ result = sw_geographic_search
116
115
 
117
116
  # TODO: this should go into stanford-mods ... but then we have to set that gem up with a Logger
118
117
  # print a message for any unrecognized encodings
119
- xvals = self.subject.geographicCode.translated_value
120
- codes = self.term_values([:subject, :geographicCode])
118
+ xvals = subject.geographicCode.translated_value
119
+ codes = term_values([:subject, :geographicCode])
121
120
  if codes && codes.size > xvals.size
122
- self.subject.geographicCode.each { |n|
121
+ subject.geographicCode.each { |n|
123
122
  if n.authority != 'marcgac' && n.authority != 'marccountry'
124
123
  sw_logger.info("#{druid} has subject geographicCode element with untranslated encoding (#{n.authority}): #{n.to_xml}")
125
124
  end
@@ -153,12 +152,12 @@ module Stanford
153
152
  def subject_other_subvy_search
154
153
  @subject_other_subvy_search ||= begin
155
154
  vals = subject_temporal ? Array.new(subject_temporal) : []
156
- gvals = self.term_values([:subject, :genre])
155
+ gvals = term_values([:subject, :genre])
157
156
  vals.concat(gvals) if gvals
158
157
 
159
158
  # print a message for any temporal encodings
160
- self.subject.temporal.each { |n|
161
- sw_logger.info("#{druid} has subject temporal element with untranslated encoding: #{n.to_xml}") if !n.encoding.empty?
159
+ subject.temporal.each { |n|
160
+ sw_logger.info("#{druid} has subject temporal element with untranslated encoding: #{n.to_xml}") unless n.encoding.empty?
162
161
  }
163
162
 
164
163
  vals.empty? ? nil : vals
@@ -180,29 +179,28 @@ module Stanford
180
179
 
181
180
  # convenience method for subject/name/namePart values (to avoid parsing the mods for the same thing multiple times)
182
181
  def subject_names
183
- @subject_names ||= self.sw_subject_names
182
+ @subject_names ||= sw_subject_names
184
183
  end
185
184
 
186
185
  # convenience method for subject/occupation values (to avoid parsing the mods for the same thing multiple times)
187
186
  def subject_occupations
188
- @subject_occupations ||= self.term_values([:subject, :occupation])
187
+ @subject_occupations ||= term_values([:subject, :occupation])
189
188
  end
190
189
 
191
190
  # convenience method for subject/temporal values (to avoid parsing the mods for the same thing multiple times)
192
191
  def subject_temporal
193
- @subject_temporal ||= self.term_values([:subject, :temporal])
192
+ @subject_temporal ||= term_values([:subject, :temporal])
194
193
  end
195
194
 
196
195
  # convenience method for subject/titleInfo values (to avoid parsing the mods for the same thing multiple times)
197
196
  def subject_titles
198
- @subject_titles ||= self.sw_subject_titles
197
+ @subject_titles ||= sw_subject_titles
199
198
  end
200
199
 
201
200
  # convenience method for subject/topic values (to avoid parsing the mods for the same thing multiple times)
202
201
  def subject_topics
203
- @subject_topics ||= self.term_values([:subject, :topic])
202
+ @subject_topics ||= term_values([:subject, :topic])
204
203
  end
205
-
206
204
  end
207
205
  end
208
206
  end
@@ -1,6 +1,6 @@
1
1
  module Stanford
2
2
  module Mods
3
3
  # this is the Ruby Gem version
4
- VERSION = "2.2.0"
4
+ VERSION = "2.2.1".freeze
5
5
  end
6
6
  end
@@ -1,6 +1,5 @@
1
1
  # encoding: utf-8
2
2
  describe "date parsing methods" do
3
-
4
3
  unparseable = [ # here to remind us of what they might look like in our data
5
4
  nil,
6
5
  '',
@@ -106,11 +105,11 @@ describe "date parsing methods" do
106
105
  'No. 15 1792' => '1792',
107
106
  's.a. [1712]' => '1712',
108
107
  'publié le 24 floréal [1796]' => '1796',
109
- "Fructidor l'an 3.e [i.e. 1795]" => '1795',
108
+ "Fructidor l'an 3.e [i.e. 1795]" => '1795'
110
109
  }
111
110
  # example string as key, expected parsed value as value
112
111
  specific_month = {
113
- '1975-05' => '1975', # vs 1918-27
112
+ '1975-05' => '1975', # vs 1918-27
114
113
  '1996 Jun' => '1996',
115
114
  'February 1798' => '1798',
116
115
  'March, 1794' => '1794',
@@ -262,7 +261,7 @@ describe "date parsing methods" do
262
261
  'March 22 d. 1794' => '1794',
263
262
  'N. 7 1796' => '1796',
264
263
  'N[ovember] 21st 1786' => '1786',
265
- 'Oct. the 2.d 1793' => '1793',
264
+ 'Oct. the 2.d 1793' => '1793'
266
265
  }
267
266
  # example string as key, expected parsed value as value
268
267
  specific_day_2_digit_year = {
@@ -285,12 +284,12 @@ describe "date parsing methods" do
285
284
  '1901, c1900' => ['1901', '1900'], # pub date is one without the c,
286
285
  '1627 [i.e. 1646]' => ['1627', '1646'],
287
286
  '1698/1715' => ['1698', '1715'],
288
- '1965,1968' => ['1965', '1968'], # revs
287
+ '1965,1968' => ['1965', '1968'], # revs
289
288
  '1965|1968' => ['1965', '1968'], # revs
290
289
  '1789 ou 1790]' => ['1789', '1790'],
291
290
  '1689 [i.e. 1688-89]' => ['1689', '1688'],
292
291
  '1598 or 1599' => ['1598', '1599'],
293
- '1890 [c1884]' => ['1890', '1884'], # pub date is one without the c
292
+ '1890 [c1884]' => ['1890', '1884'], # pub date is one without the c
294
293
  '1873,c1868' => ['1873', '1868'], # # pub date is one without the c
295
294
  '1872-1877 [t.5, 1874]' => ['1872', '1873', '1874', '1875', '1876', '1877'],
296
295
  '1809 [ca. 1810]' => ['1809', '1810'],
@@ -324,7 +323,7 @@ describe "date parsing methods" do
324
323
  }
325
324
  # example string as key, expected parsed value as value
326
325
  multiple_years_4_digits_once = {
327
- '1918-20' => ['1918', '1919', '1920'], # vs. 1961-04
326
+ '1918-20' => ['1918', '1919', '1920'], # vs. 1961-04
328
327
  '1965-8' => ['1965', '1966', '1967', '1968'], # revs
329
328
  '[1846-51]' => ['1846', '1847', '1848', '1849', '1850', '1851']
330
329
  }
@@ -416,8 +415,8 @@ describe "date parsing methods" do
416
415
  .merge(century_only)
417
416
  .merge(brackets_in_middle_of_year)
418
417
  .merge(invalid_but_can_get_year).each do |example, expected|
419
- expected = expected.to_i.to_s if expected.match(/^\d+$/)
420
- expected = "#{expected} A.D." if expected.match(/^\d{1,3}$/)
418
+ expected = expected.to_i.to_s if expected =~ /^\d+$/
419
+ expected = "#{expected} A.D." if expected =~ /^\d{1,3}$/
421
420
  it "#{expected} for single value #{example}" do
422
421
  expect(Stanford::Mods::DateParsing.new(example).date_str_for_display).to eq expected
423
422
  end
@@ -425,7 +424,7 @@ describe "date parsing methods" do
425
424
 
426
425
  decade_only
427
426
  .merge(decade_only_4_digits).each do |example, expected|
428
- expected = "#{expected.first.to_i}s" if expected.first.match(/^\d+$/)
427
+ expected = "#{expected.first.to_i}s" if expected.first =~ /^\d+$/
429
428
  it "#{expected} for decade #{example}" do
430
429
  expect(Stanford::Mods::DateParsing.new(example).date_str_for_display).to eq expected
431
430
  end
@@ -445,7 +444,7 @@ describe "date parsing methods" do
445
444
  expect(Stanford::Mods::DateParsing.new(example).date_str_for_display).to eq exp
446
445
  end
447
446
  else
448
- expected = "#{expected.to_i} A.D." if expected.match(/^\d+$/)
447
+ expected = "#{expected.to_i} A.D." if expected =~ /^\d+$/
449
448
  it "#{expected} for #{example}" do
450
449
  expect(Stanford::Mods::DateParsing.new(example).date_str_for_display).to eq expected
451
450
  end
@@ -601,9 +600,9 @@ describe "date parsing methods" do
601
600
  'random text' => false,
602
601
  nil => false
603
602
  }.each do |example, expected|
604
- it "#{expected} for #{example}" do
605
- expect(Stanford::Mods::DateParsing.year_str_valid?(example)).to eq expected
606
- end
603
+ it "#{expected} for #{example}" do
604
+ expect(Stanford::Mods::DateParsing.year_str_valid?(example)).to eq expected
605
+ end
607
606
  end
608
607
  end
609
608
 
@@ -625,9 +624,9 @@ describe "date parsing methods" do
625
624
  'random text' => false,
626
625
  nil => false
627
626
  }.each do |example, expected|
628
- it "#{expected} for #{example}" do
629
- expect(Stanford::Mods::DateParsing.year_int_valid?(example)).to eq expected
630
- end
627
+ it "#{expected} for #{example}" do
628
+ expect(Stanford::Mods::DateParsing.year_int_valid?(example)).to eq expected
629
+ end
631
630
  end
632
631
  it 'true for 0000' do
633
632
  expect(Stanford::Mods::DateParsing.year_int_valid?(0000)).to eq true
@@ -796,7 +795,7 @@ describe "date parsing methods" do
796
795
 
797
796
  context '#display_str_for_early_numeric' do
798
797
  early_numeric_dates.each do |example, expected|
799
- expected = expected.to_i.to_s if expected.match(/^\d+$/)
798
+ expected = expected.to_i.to_s if expected =~ /^\d+$/
800
799
  if example.start_with?('-') || example == '0'
801
800
  exp = "#{example[1..-1].to_i + 1} B.C."
802
801
  it "#{exp} for #{example}" do
@@ -897,5 +896,4 @@ describe "date parsing methods" do
897
896
  end
898
897
  end
899
898
  end
900
-
901
899
  end
@@ -1297,4 +1297,4 @@ SEARCHWORKS_IMPRINT_DATA = {
1297
1297
  # water
1298
1298
  # wilpf?
1299
1299
  # yotsuba
1300
- }
1300
+ }.freeze
@@ -976,4 +976,4 @@ SEARCHWORKS_PUB_DATE_DATA = {
976
976
  # water
977
977
  # wilpf?
978
978
  # yotsuba
979
- }
979
+ }.freeze
@@ -313,4 +313,4 @@ SPOTLIGHT_PUB_DATE_DATA = {
313
313
  '<dateIssued encoding="marc">1786</dateIssued>' +
314
314
  mods_origin_info_end_str => ['1786', '1786']
315
315
  }
316
- }
316
+ }.freeze
@@ -1,8 +1,5 @@
1
1
  # encoding: utf-8
2
- require 'spec_helper'
3
-
4
2
  describe "Cartographic coordinates" do
5
-
6
3
  let(:smods_rec) { Stanford::Mods::Record.new }
7
4
  let(:no_coord) do
8
5
  <<-EOF
@@ -16,7 +13,7 @@ describe "Cartographic coordinates" do
16
13
  </mods>
17
14
  EOF
18
15
  end
19
- let(:with_coords) do
16
+ let(:with_coords) do
20
17
  <<-EOF
21
18
  <mods xmlns="#{Mods::MODS_NS}">
22
19
  <subject>
@@ -28,7 +25,6 @@ describe "Cartographic coordinates" do
28
25
  </mods>
29
26
  EOF
30
27
  end
31
-
32
28
  let(:with_bad_data) do
33
29
  <<-EOF
34
30
  <mods xmlns="#{Mods::MODS_NS}">
@@ -42,6 +38,10 @@ describe "Cartographic coordinates" do
42
38
  EOF
43
39
  end
44
40
 
41
+ it 'has access to logger' do
42
+ expect(smods_rec.logger).to be_a Logger
43
+ end
44
+
45
45
  context "coordinates" do
46
46
  it "returns empty array if no coordinates in the mods" do
47
47
  smods_rec.from_str(no_coord)
@@ -83,3 +83,49 @@ describe "Cartographic coordinates" do
83
83
  end
84
84
  end
85
85
  end # describe Cartographic coordinates
86
+
87
+ describe '#geo_extension_as_envelope' do
88
+ let(:modsbody) { '' }
89
+ let(:mods) do
90
+ rec = Stanford::Mods::Record.new
91
+ rec.from_str %(<mods xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
92
+ xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns="http://www.loc.gov/mods/v3" version="3.5"
93
+ xsi:schemaLocation="http://www.loc.gov/mods/v3 http://www.loc.gov/standards/mods/v3/mods-3-5.xsd">#{modsbody}</mods>)
94
+ rec
95
+ end
96
+
97
+ it 'without data, returns emtpy array' do
98
+ expect(mods.geo_extensions_as_envelope).to eq []
99
+ end
100
+
101
+ describe 'with data' do
102
+ let(:modsbody) do
103
+ <<-EOF
104
+ <extension displayLabel="geo">
105
+ <rdf:RDF xmlns:gml="http://www.opengis.net/gml/3.2/" xmlns:dc="http://purl.org/dc/elements/1.1/">
106
+ <rdf:Description rdf:about="http://purl.stanford.edu/cw222pt0426">
107
+ <dc:format>image/jpeg</dc:format>
108
+ <dc:type>Image</dc:type>
109
+ <gml:boundedBy>
110
+ <gml:Envelope>
111
+ <gml:lowerCorner>-122.191292 37.4063388</gml:lowerCorner>
112
+ <gml:upperCorner>-122.149475 37.4435369</gml:upperCorner>
113
+ </gml:Envelope>
114
+ </gml:boundedBy>
115
+ </rdf:Description>
116
+ </rdf:RDF>
117
+ </extension>
118
+ EOF
119
+ end
120
+
121
+ it 'logs error and returns emtpy array' do
122
+ allow(mods.mods_ng_xml).to receive(:extension).and_raise(RuntimeError)
123
+ expect(mods.logger).to receive(:warn).with(/failure parsing.*RuntimeError/)
124
+ expect(mods.geo_extensions_as_envelope).to eq []
125
+ end
126
+
127
+ it 'extract envelope strings' do
128
+ expect(mods.geo_extensions_as_envelope).to eq ["ENVELOPE(-122.191292, -122.149475, 37.4435369, 37.4063388)"]
129
+ end
130
+ end
131
+ end
data/spec/imprint_spec.rb CHANGED
@@ -1,5 +1,3 @@
1
- require 'spec_helper'
2
-
3
1
  def stanford_mods_imprint(smods_rec)
4
2
  Stanford::Mods::Imprint.new(smods_rec.origin_info)
5
3
  end
@@ -59,7 +57,7 @@ describe Stanford::Mods::Imprint do
59
57
  end
60
58
 
61
59
  context 'date_is_decade?' do
62
- [ '156u',
60
+ ['156u',
63
61
  '167-?]',
64
62
  '[171-?]',
65
63
  '[189-]',
@@ -78,7 +76,7 @@ describe Stanford::Mods::Imprint do
78
76
  expect(imp.send(:date_is_decade?, element)).to be_truthy
79
77
  end
80
78
  end
81
- [ '1950s',
79
+ ['1950s',
82
80
  "1950's",
83
81
  'before 1950s after'
84
82
  ].each do |example|
@@ -136,7 +134,7 @@ describe Stanford::Mods::Imprint do
136
134
  end
137
135
 
138
136
  context 'date_is_century?' do
139
- [ '17uu',
137
+ ['17uu',
140
138
  '17--?',
141
139
  'before [16--] after'
142
140
  ].each do |example|
@@ -149,7 +147,7 @@ describe Stanford::Mods::Imprint do
149
147
  expect(imp.send(:date_is_century?, element)).to be_truthy
150
148
  end
151
149
  end
152
- [ '18th century CE',
150
+ ['18th century CE',
153
151
  "before 5th century after"
154
152
  ].each do |example|
155
153
  it 'false when no century string to change' do
@@ -1,6 +1,4 @@
1
1
  # encoding: utf-8
2
- require 'spec_helper'
3
-
4
2
  describe Stanford::Mods::Coordinate do
5
3
  describe '#valid' do
6
4
  it 'is valid for well-formed coordinates' do
data/spec/name_spec.rb CHANGED
@@ -1,5 +1,3 @@
1
- require 'spec_helper'
2
-
3
1
  describe "name/author concepts" do
4
2
  let(:smods_rec) { Stanford::Mods::Record.new }
5
3
  let(:mods_start) { "<mods xmlns=\"#{Mods::MODS_NS}\">" }
@@ -1,5 +1,4 @@
1
1
  describe "computations from /originInfo field" do
2
-
3
2
  let(:smods_rec) { Stanford::Mods::Record.new }
4
3
 
5
4
  # used for single examples
@@ -24,7 +23,7 @@ describe "computations from /originInfo field" do
24
23
  <dateCreated>1999</dateCreated>' +
25
24
  mods_origin_info_end_str
26
25
  smods_rec.from_str(mods_str)
27
- expect(smods_rec.send(method_sym)).to eq method_sym.to_s.match(/int/) ? 2005 : '2005'
26
+ expect(smods_rec.send(method_sym)).to eq method_sym.to_s =~ /int/ ? 2005 : '2005'
28
27
  end
29
28
  it 'respects ignore_approximate param' do
30
29
  mods_str = mods_origin_info_start_str +
@@ -32,8 +31,8 @@ describe "computations from /originInfo field" do
32
31
  '<dateCreated point="end">1599</dateCreated>' +
33
32
  mods_origin_info_end_str
34
33
  smods_rec.from_str(mods_str)
35
- expect(smods_rec.send(method_sym, true)).to eq method_sym.to_s.match(/int/) ? 1599 : '1599'
36
- expect(smods_rec.send(method_sym, false)).to eq method_sym.to_s.match(/int/) ? 1000 : '1000'
34
+ expect(smods_rec.send(method_sym, true)).to eq method_sym.to_s =~ /int/ ? 1599 : '1599'
35
+ expect(smods_rec.send(method_sym, false)).to eq method_sym.to_s =~ /int/ ? 1000 : '1000'
37
36
  end
38
37
  it 'nil if ignore_approximate and all dates are approximate' do
39
38
  mods_str = mods_origin_info_start_str +
@@ -42,7 +41,7 @@ describe "computations from /originInfo field" do
42
41
  mods_origin_info_end_str
43
42
  smods_rec.from_str(mods_str)
44
43
  expect(smods_rec.send(method_sym, true)).to eq nil
45
- expect(smods_rec.send(method_sym, false)).to eq method_sym.to_s.match(/int/) ? 1000 : '1000'
44
+ expect(smods_rec.send(method_sym, false)).to eq method_sym.to_s =~ /int/ ? 1000 : '1000'
46
45
  end
47
46
  it 'respects ignore_approximate even for keyDate' do
48
47
  mods_str = mods_origin_info_start_str +
@@ -50,8 +49,8 @@ describe "computations from /originInfo field" do
50
49
  '<dateCreated point="end">1599</dateCreated>' +
51
50
  mods_origin_info_end_str
52
51
  smods_rec.from_str(mods_str)
53
- expect(smods_rec.send(method_sym, true)).to eq method_sym.to_s.match(/int/) ? 1599 : '1599'
54
- expect(smods_rec.send(method_sym, false)).to eq method_sym.to_s.match(/int/) ? 1000 : '1000'
52
+ expect(smods_rec.send(method_sym, true)).to eq method_sym.to_s =~ /int/ ? 1599 : '1599'
53
+ expect(smods_rec.send(method_sym, false)).to eq method_sym.to_s =~ /int/ ? 1000 : '1000'
55
54
  end
56
55
  it 'uses dateCaptured if no dateIssued or dateCreated' do
57
56
  # for web archive seed files
@@ -60,19 +59,18 @@ describe "computations from /originInfo field" do
60
59
  '<dateCaptured encoding="w3cdtf" point="end">20151218111111</dateCaptured>' +
61
60
  mods_origin_info_end_str
62
61
  smods_rec.from_str(mods_str)
63
- expect(smods_rec.send(method_sym)).to eq method_sym.to_s.match(/int/) ? 2015 : '2015'
62
+ expect(smods_rec.send(method_sym)).to eq method_sym.to_s =~ /int/ ? 2015 : '2015'
64
63
  end
65
64
  context 'spotlight actual data' do
66
65
  require 'fixtures/spotlight_pub_date_data'
67
66
  SPOTLIGHT_PUB_DATE_DATA.each_pair.each do |coll_name, coll_data|
68
67
  # papyri - the only Spotlight data with BC dates
69
- unless coll_name == 'papyri' && method_sym == :pub_year_int
70
- coll_data.each_pair do |mods_str, exp_vals|
71
- expected = exp_vals[exp_val_position]
72
- it "#{expected} for rec in #{coll_name}" do
73
- smods_rec.from_str(mods_str)
74
- expect(smods_rec.send(method_sym)).to eq((method_sym.to_s.match(/int/) ? expected.to_i : expected)) if expected
75
- end
68
+ next if coll_name == 'papyri' && method_sym == :pub_year_int
69
+ coll_data.each_pair do |mods_str, exp_vals|
70
+ expected = exp_vals[exp_val_position]
71
+ it "#{expected} for rec in #{coll_name}" do
72
+ smods_rec.from_str(mods_str)
73
+ expect(smods_rec.send(method_sym)).to eq((method_sym.to_s =~ /int/ ? expected.to_i : expected)) if expected
76
74
  end
77
75
  end
78
76
  end
@@ -163,7 +161,7 @@ describe "computations from /originInfo field" do
163
161
  '<dateIssued keyDate="yes">2014</dateIssued>' +
164
162
  mods_origin_info_end_str
165
163
  smods_rec.from_str(mods_str)
166
- expect(smods_rec.send(method_sym, smods_rec.date_issued_elements)).to eq method_sym.to_s.match(/int/) ? 2014 : '2014'
164
+ expect(smods_rec.send(method_sym, smods_rec.date_issued_elements)).to eq method_sym.to_s =~ /int/ ? 2014 : '2014'
167
165
  end
168
166
  it 'ignores invalid keyDate value' do
169
167
  mods_str = mods_origin_info_start_str +
@@ -171,7 +169,7 @@ describe "computations from /originInfo field" do
171
169
  '<dateIssued>1499</dateIssued>' +
172
170
  mods_origin_info_end_str
173
171
  smods_rec.from_str(mods_str)
174
- expect(smods_rec.send(method_sym, smods_rec.date_issued_elements)).to eq method_sym.to_s.match(/int/) ? 1499 : '1499'
172
+ expect(smods_rec.send(method_sym, smods_rec.date_issued_elements)).to eq method_sym.to_s =~ /int/ ? 1499 : '1499'
175
173
  end
176
174
  it 'calls earliest_year_str if multiple keyDates present' do
177
175
  mods_str = mods_origin_info_start_str +
@@ -179,7 +177,7 @@ describe "computations from /originInfo field" do
179
177
  '<dateCreated keyDate="yes">2001</dateCreated>' +
180
178
  mods_origin_info_end_str
181
179
  smods_rec.from_str(mods_str)
182
- if method_sym.to_s.match(/int/)
180
+ if method_sym.to_s =~ /int/
183
181
  expect(Stanford::Mods::Record).to receive(:earliest_year_int).with(smods_rec.date_created_elements)
184
182
  else
185
183
  expect(Stanford::Mods::Record).to receive(:earliest_year_str).with(smods_rec.date_created_elements)
@@ -193,7 +191,7 @@ describe "computations from /originInfo field" do
193
191
  '<dateIssued point="end" qualifier="questionable">uuuu</dateIssued>' +
194
192
  mods_origin_info_end_str
195
193
  smods_rec.from_str(mods_str)
196
- if method_sym.to_s.match(/int/)
194
+ if method_sym.to_s =~ /int/
197
195
  expect(Stanford::Mods::Record).to receive(:earliest_year_int).with(smods_rec.date_issued_elements)
198
196
  else
199
197
  expect(Stanford::Mods::Record).to receive(:earliest_year_str).with(smods_rec.date_issued_elements)
@@ -208,21 +206,21 @@ describe "computations from /originInfo field" do
208
206
  '<dateIssued encoding="w3cdtf">1300</dateIssued>' +
209
207
  mods_origin_info_end_str
210
208
  smods_rec.from_str(mods_str)
211
- expect(smods_rec.send(method_sym, smods_rec.date_issued_elements)).to eq method_sym.to_s.match(/int/) ? 1100 : '1100'
209
+ expect(smods_rec.send(method_sym, smods_rec.date_issued_elements)).to eq method_sym.to_s =~ /int/ ? 1100 : '1100'
212
210
  mods_str = mods_origin_info_start_str +
213
211
  '<dateIssued>1200</dateIssued>' +
214
212
  '<dateIssued encoding="marc">1300</dateIssued>' +
215
213
  '<dateIssued encoding="w3cdtf" keyDate="yes">1100</dateIssued>' +
216
214
  mods_origin_info_end_str
217
215
  smods_rec.from_str(mods_str)
218
- expect(smods_rec.send(method_sym, smods_rec.date_issued_elements)).to eq method_sym.to_s.match(/int/) ? 1100 : '1100'
216
+ expect(smods_rec.send(method_sym, smods_rec.date_issued_elements)).to eq method_sym.to_s =~ /int/ ? 1100 : '1100'
219
217
  mods_str = mods_origin_info_start_str +
220
218
  '<dateIssued>1300</dateIssued>' +
221
219
  '<dateIssued encoding="marc" keyDate="yes">1100</dateIssued>' +
222
220
  '<dateIssued encoding="w3cdtf">1200</dateIssued>' +
223
221
  mods_origin_info_end_str
224
222
  smods_rec.from_str(mods_str)
225
- expect(smods_rec.send(method_sym, smods_rec.date_issued_elements)).to eq method_sym.to_s.match(/int/) ? 1100 : '1100'
223
+ expect(smods_rec.send(method_sym, smods_rec.date_issued_elements)).to eq method_sym.to_s =~ /int/ ? 1100 : '1100'
226
224
  end
227
225
  end
228
226
 
@@ -307,7 +305,7 @@ describe "computations from /originInfo field" do
307
305
  end
308
306
  context "retains element when attribute qualifer=" do
309
307
  ['inferred', 'invalid_attr_val'].each do |attr_val|
310
- let(:qual_attr_val) { attr_val }
308
+ let(:qual_attr_val) { attr_val }
311
309
  it attr_val do
312
310
  smods_rec.from_str mods_rec
313
311
  result = smods_rec.date_issued_elements(true)
@@ -319,7 +317,7 @@ describe "computations from /originInfo field" do
319
317
  end
320
318
  end
321
319
 
322
- let(:start_str) {"#{mods_origin_info_start_str}<dateIssued>2015</dateIssued>"}
320
+ let(:start_str) { "#{mods_origin_info_start_str}<dateIssued>2015</dateIssued>" }
323
321
  it 'retains element without qualifier attribute"' do
324
322
  m = start_str + '<dateIssued>1666</dateIssued>' + mods_origin_info_end_str
325
323
  smods_rec.from_str m
@@ -376,7 +374,7 @@ describe "computations from /originInfo field" do
376
374
  end
377
375
  context "retains element when attribute qualifer=" do
378
376
  ['inferred', 'invalid_attr_val'].each do |attr_val|
379
- let(:qual_attr_val) { attr_val }
377
+ let(:qual_attr_val) { attr_val }
380
378
  it attr_val do
381
379
  smods_rec.from_str mods_rec
382
380
  result = smods_rec.date_created_elements(true)
@@ -388,7 +386,7 @@ describe "computations from /originInfo field" do
388
386
  end
389
387
  end
390
388
 
391
- let(:start_str) {"#{mods_origin_info_start_str}<dateCreated>2015</dateCreated>"}
389
+ let(:start_str) { "#{mods_origin_info_start_str}<dateCreated>2015</dateCreated>" }
392
390
  it 'retains element without qualifier attribute"' do
393
391
  m = start_str + '<dateCreated>1666</dateCreated>' + mods_origin_info_end_str
394
392
  smods_rec.from_str m
@@ -468,7 +466,7 @@ describe "computations from /originInfo field" do
468
466
  <dateIssued qualifier='#{attr_value}'>1968</dateIssued>
469
467
  #{mods_origin_info_end_str}"
470
468
  end
471
- it "#{expected}" do
469
+ it expected.to_s do
472
470
  smods_rec.from_str(mods_str)
473
471
  date_el = smods_rec.date_issued_elements.first
474
472
  expect(Stanford::Mods::Record.date_is_approximate?(date_el)).to eq expected
@@ -491,4 +489,4 @@ describe "computations from /originInfo field" do
491
489
  expect(smods_rec.send(:get_u_year, ["9999"])).to be_nil
492
490
  end
493
491
  end
494
- end
492
+ end