stanford-mods 3.3.9 → 3.3.10

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '0729c421d4ffde7b9818ad6012d19ec0fc146c36fa60aa0f9384c2d02d87138f'
4
- data.tar.gz: b14ae5c1aeb368ca68fc37c8f9021b99f95af3e670edb7e0b822aeba1f1ecc5d
3
+ metadata.gz: cb1b017fccf0e3f74a5c0594e5a21a43f7816055b2c67486392af2308ce85860
4
+ data.tar.gz: b992e7323c4e096d0714d5391a9c4206745c536f99b2fad92fbe9b1affb89645
5
5
  SHA512:
6
- metadata.gz: dfe5bb3f80cdd0daead674f3a5e7d382dd05c4923efc7b35de192a2b2771e42fa8c78ae489b3790bc7b23a737902790e5e6e34f959008317f028bbab8e4f40d1
7
- data.tar.gz: '01498aa51983570655d823eb897507e5a0c0954689d5040ced4b813031f767fc120c25298a10d797c8ad69b2d9398cea405572c54b13a24697f787d3318608b1'
6
+ metadata.gz: d28ee675c3f53cf6052b732883487475ec44519a5a79241a0de4e1aa798daae208a6f6d5c951d561745a8035b35f5f8716788f9e7520833a5cdc49d19533d832
7
+ data.tar.gz: e992ac4964d4b857084427c6a2e291c1c2cbe219d5b524be328a86aa1670cbe0993cc803d66c374b0460ba41239318b5f05533f9060fac7415220983886a7ca9
@@ -10,6 +10,8 @@ module Stanford
10
10
  # however, the date_parsing class only does years, and this does finer tuned dates and also
11
11
  # reformats them according to the encoding.
12
12
  class Imprint
13
+ BCE_CHAR_SORT_MAP = { '0' => '9', '1' => '8', '2' => '7', '3' => '6', '4' => '5', '5' => '4', '6' => '3', '7' => '2', '8' => '1', '9' => '0' }.freeze
14
+
13
15
  attr_reader :element
14
16
 
15
17
  # @param [Nokogiri::XML::Node] an originInfo node
@@ -170,19 +172,25 @@ module Stanford
170
172
  date.year
171
173
  end
172
174
 
173
- str = if year < 1
174
- (-1 * year - 1000).to_s
175
+ str = if year > 0
176
+ # for CE dates, we can just pad them out to 4 digits and sort normally...
177
+ year.to_s.rjust(4, "0")
175
178
  else
176
- year.to_s
179
+ # ... but for BCE, because we're sorting lexically, we need to invert the digits (replacing 0 with 9, 1 with 8, etc.),
180
+ # we prefix it with a hyphen (which will sort before any digit) and the number of digits (also inverted) to get
181
+ # it to sort correctly.
182
+ inverted_year = year.abs.to_s.chars.map { |c| BCE_CHAR_SORT_MAP[c] }.join
183
+ length_prefix = BCE_CHAR_SORT_MAP[inverted_year.to_s.length.to_s]
184
+ "-#{length_prefix}#{inverted_year}"
177
185
  end
178
186
 
179
187
  case value.precision
180
188
  when :decade
181
- str[0..2] + "-"
189
+ str[0...-1] + "-"
182
190
  when :century
183
- str[0..1] + "--"
191
+ str[0...-2] + "--"
184
192
  else
185
- str.rjust(4, "0")
193
+ str
186
194
  end
187
195
  end
188
196
 
@@ -1,6 +1,6 @@
1
1
  module Stanford
2
2
  module Mods
3
3
  # this is the Ruby Gem version
4
- VERSION = '3.3.9'.freeze
4
+ VERSION = '3.3.10'.freeze
5
5
  end
6
6
  end
@@ -383,7 +383,7 @@ describe "computations from /originInfo field" do
383
383
  end
384
384
 
385
385
  it 'returns the earliest date with the funky lexical sort encoding' do
386
- expect(record.pub_year_sort_str).to eq '-751'
386
+ expect(record.pub_year_sort_str).to eq '-6750'
387
387
  end
388
388
  end
389
389
 
@@ -400,7 +400,23 @@ describe "computations from /originInfo field" do
400
400
  end
401
401
 
402
402
  it 'returns the earliest date of the range with the funky lexical sort encoding' do
403
- expect(record.pub_year_sort_str).to eq '-751'
403
+ expect(record.pub_year_sort_str).to eq '-6750'
404
+ end
405
+ end
406
+
407
+ context 'with a really old BCE date (e.g. ky899rv1161)' do
408
+ let(:modsxml) do
409
+ <<-EOF
410
+ <mods xmlns="http://www.loc.gov/mods/v3">
411
+ <originInfo>
412
+ <dateIssued encoding="edtf">Y-12345</dateIssued>
413
+ </originInfo>
414
+ </mods>
415
+ EOF
416
+ end
417
+
418
+ it 'returns the earliest date of the range with the funky lexical sort encoding' do
419
+ expect(record.pub_year_sort_str).to eq '-487654'
404
420
  end
405
421
  end
406
422
 
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.3.9
4
+ version: 3.3.10
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: 2023-12-01 00:00:00.000000000 Z
12
+ date: 2025-02-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: mods
@@ -214,7 +214,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
214
214
  - !ruby/object:Gem::Version
215
215
  version: '0'
216
216
  requirements: []
217
- rubygems_version: 3.4.13
217
+ rubygems_version: 3.5.9
218
218
  signing_key:
219
219
  specification_version: 4
220
220
  summary: Stanford specific wrangling of MODS metadata