stanford-mods 3.0.0 → 3.1.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
  SHA256:
3
- metadata.gz: 70d3b7093c830baa3c12f4c2c438549eb451fa4b6bb6c57f458382f0e8e53dc2
4
- data.tar.gz: 044edaeef524c4a701ebbc0e25f08d0c3fb5068b04cc36ab8769772004a73a85
3
+ metadata.gz: 22cc1cc8aafefb053ea3856e273e17be7089862160e91d87c483393b60c02aca
4
+ data.tar.gz: dbeea673e2c79744215c278ebf2fa73b78de3de7f79602590948bf4ee117b1df
5
5
  SHA512:
6
- metadata.gz: '097830e7c3b1136a279dfce41ac426ae860ab020f27bb1550a3f2a5f23b7fcbc1c7f7952f35f06a44aed7100d0d410c39adcbb17a70b270174c85b757d1aca4b'
7
- data.tar.gz: 7aa1c33f53fdbd4160d99a14739b4dcbd37950f4d8ab8238ee1886d4b6db4aaa9b5dec4c92f74842db80aa9839ec2d7e27a570a4fb7cde4862afc54b79c9e6a4
6
+ metadata.gz: fb3d7b5761a6e4811dd85b6d4972ce238e5b507e957d617b5e4a3935bcd3e9f791176d250418a198d2b68a63babfc58dcb9c39d1b8b4fbbbdd01eecc504fa8a2
7
+ data.tar.gz: 3fe0f6181376c4cca9618a90e9a03244328f3a93a16ea55f1b5a72c7f842ddd0de8addbfb2da75efa4875bc4c04e4dd73caaad543745faf9461da7928566487e
@@ -65,11 +65,14 @@ module Stanford
65
65
  # @param [String] point coordinate point in degrees notation
66
66
  # @return [Float] converted value in decimal notation
67
67
  def coord_to_decimal(point)
68
- regex = /(?<dir>[NESW])\s*(?<deg>\d+)[°⁰º](?:(?<min>\d+)[ʹ'])?(?:(?<sec>\d+)[ʺ"])?/
68
+ regex = Regexp.union(
69
+ /(?<dir>[NESW])\s*(?<deg>\d+)[°⁰º](?:(?<min>\d+)[ʹ'])?(?:(?<sec>\d+)[ʺ"])?/,
70
+ /^\s*(?<dir>[NESW])\s*(?<deg>\d+(?:[.]\d+)?)\s*$/
71
+ )
69
72
  match = regex.match(point)
70
73
  return Float::INFINITY unless match
71
74
 
72
- dec = match['deg'].to_i
75
+ dec = match['deg'].to_f
73
76
  dec += match['min'].to_f / 60
74
77
  dec += match['sec'].to_f / 60 / 60
75
78
  dec = -1 * dec if match['dir'] == 'W' || match['dir'] == 'S'
@@ -166,8 +166,26 @@ module Stanford
166
166
  return text.strip unless text =~ /^-?\d+$/ || text =~ /^[\dXxu?-]{4}$/
167
167
  end
168
168
 
169
- # Delegate to the appropriate decoding method, if any
170
- case value.precision
169
+ if date.is_a?(EDTF::Interval)
170
+ if value.precision == :century || value.precision == :decade
171
+ return format_date(date, value.precision)
172
+ end
173
+
174
+ range = [
175
+ format_date(date.min, date.min.precision),
176
+ format_date(date.max, date.max.precision)
177
+ ].uniq.compact
178
+
179
+ return text.strip if range.empty?
180
+
181
+ range.join(' - ')
182
+ else
183
+ format_date(date, value.precision) || text.strip
184
+ end
185
+ end
186
+
187
+ def format_date(date, precision)
188
+ case precision
171
189
  when :day
172
190
  date.strftime('%B %e, %Y')
173
191
  when :month
@@ -183,24 +201,31 @@ module Stanford
183
201
  year.to_s
184
202
  end
185
203
  when :century
186
- return "#{(date.to_s[0..1].to_i + 1).ordinalize} century"
204
+ if date.year.negative?
205
+ "#{((date.year / 100).abs + 1).ordinalize} century B.C."
206
+ else
207
+ "#{((date.year / 100) + 1).ordinalize} century"
208
+ end
187
209
  when :decade
188
- return "#{date.year}s"
189
- else
190
- text.strip
210
+ "#{date.year}s"
191
211
  end
192
212
  end
193
213
 
194
214
  # Decoded date with "B.C." or "A.D." and qualifier markers. See (outdated):
195
215
  # https://consul.stanford.edu/display/chimera/MODS+display+rules#MODSdisplayrules-3b.%3CoriginInfo%3E
196
216
  def qualified_value
197
- date = decoded_value
198
-
199
- return "[ca. #{date}]" if qualifier == 'approximate'
200
- return "[#{date}?]" if qualifier == 'questionable'
201
- return "[#{date}]" if qualifier == 'inferred'
217
+ qualified_format = case qualifier
218
+ when 'approximate'
219
+ '[ca. %s]'
220
+ when 'questionable'
221
+ '[%s?]'
222
+ when 'inferred'
223
+ '[%s]'
224
+ else
225
+ '%s'
226
+ end
202
227
 
203
- date
228
+ format(qualified_format, decoded_value)
204
229
  end
205
230
  end
206
231
 
@@ -1,6 +1,6 @@
1
1
  module Stanford
2
2
  module Mods
3
3
  # this is the Ruby Gem version
4
- VERSION = '3.0.0'.freeze
4
+ VERSION = '3.1.0'.freeze
5
5
  end
6
6
  end
data/spec/imprint_spec.rb CHANGED
@@ -189,6 +189,31 @@ describe Stanford::Mods::Imprint do
189
189
  expect(updated_element).to eq 'April 2, 1948'
190
190
  end
191
191
 
192
+ it 'handles very precise EDTF ranges' do
193
+ smods_rec.from_str <<-XML
194
+ #{mods_origin_info_start_str}
195
+ <dateIssued encoding="edtf">2014-01/2020-12-31</dateIssued>
196
+ #{mods_origin_info_end_str}
197
+ XML
198
+
199
+ imp = stanford_mods_imprint(smods_rec)
200
+ updated_element = imp.send(:date_str)
201
+ expect(updated_element).to eq 'January 2014 - December 31, 2020'
202
+ end
203
+
204
+ xit 'handles BC EDTF centuries' do
205
+ # ruby-edtf apparently can't handle this format
206
+ smods_rec.from_str <<-XML
207
+ #{mods_origin_info_start_str}
208
+ <dateIssued encoding="edtf">-09XX</dateIssued>
209
+ #{mods_origin_info_end_str}
210
+ XML
211
+
212
+ imp = stanford_mods_imprint(smods_rec)
213
+ updated_element = imp.send(:date_str)
214
+ expect(updated_element).to eq '10th century B.C.'
215
+ end
216
+
192
217
  it 'handles the approximate qualifier' do
193
218
  smods_rec.from_str <<-XML
194
219
  #{mods_origin_info_start_str}
@@ -9,10 +9,6 @@ describe Stanford::Mods::Coordinate do
9
9
  expect(described_class.new('W80°--E100°/N487°--S42°')).not_to be_valid
10
10
  end
11
11
 
12
- it 'rejects coordinates without degree symbols' do
13
- expect(described_class.new('W 650--W 100/N 700--N 550')).not_to be_valid
14
- end
15
-
16
12
  it 'rejects malformed coordinates' do
17
13
  expect(described_class.new('(E29°--E35/°S12°--S16°).')).not_to be_valid
18
14
  end
@@ -43,7 +39,9 @@ describe Stanford::Mods::Coordinate do
43
39
  %((W 170⁰--E 55⁰/N 40⁰--S 36⁰).) =>
44
40
  '-170.0 -36.0 55.0 40.0', # superscript 0 is almost a degree character..
45
41
  %((W 0°-W 0°/S 90°---S 90°)) =>
46
- '-0.0 -90.0 -0.0 -90.0' # one dash, two dashes, three dashes.. what's the difference?
42
+ '-0.0 -90.0 -0.0 -90.0', # one dash, two dashes, three dashes.. what's the difference?
43
+ %((W 030.6--E 068.1/N 041.7--S 042.4)) =>
44
+ '-30.6 -42.4 68.1 41.7'
47
45
  }.each do |value, expected|
48
46
  describe 'parsing' do
49
47
  let(:subject) { described_class.new(value) }
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: 3.0.0
4
+ version: 3.1.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: 2022-02-02 00:00:00.000000000 Z
12
+ date: 2022-05-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: mods