stanford-mods 3.3.9 → 3.3.11

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: 885964c534e2c709a314a1d4d01e6f7f4cc4ac04ba04976d59c4ec699854c017
4
+ data.tar.gz: 6d305fe8a02ccd15a2571ae8295207553966841513143013d01cc7731d3e429e
5
5
  SHA512:
6
- metadata.gz: dfe5bb3f80cdd0daead674f3a5e7d382dd05c4923efc7b35de192a2b2771e42fa8c78ae489b3790bc7b23a737902790e5e6e34f959008317f028bbab8e4f40d1
7
- data.tar.gz: '01498aa51983570655d823eb897507e5a0c0954689d5040ced4b813031f767fc120c25298a10d797c8ad69b2d9398cea405572c54b13a24697f787d3318608b1'
6
+ metadata.gz: 6bb746a838909b70a9000ebab153be83bc0cf6b490dc037e997d9b2c64b222e48b23eb82f8bff4c7c8ec820f612dc748405830a7a8d82bcad03459b0d194f406
7
+ data.tar.gz: 44543ab5586fb344900af3b70b478e01e1e988368db343456a79b4a19d566423ad3372a4359d188633be6ecf82280e03ddb9b06ee0fba29401856eb7ec0e164e
@@ -74,14 +74,18 @@ module Stanford
74
74
  end
75
75
 
76
76
  # Values are the contents of:
77
- # all subject subelements except subject/cartographic plus genre top level element
77
+ # all subject subelements except subject/cartographic plus genre top level element
78
78
  # @return [Array<String>] values for the subject_all_search Solr field for this document or nil if none
79
79
  def subject_all_search
80
- topic_search + geographic_search + subject_other_search + subject_other_subvy_search
80
+ topic_search + geographic_search + subject_other_search + subject_other_subvy_search + top_level_genres
81
81
  end
82
82
 
83
83
  protected #----------------------------------------------------------
84
84
 
85
+ def top_level_genres
86
+ term_values(:genre) || []
87
+ end
88
+
85
89
  # convenience method for subject/name/namePart values (to avoid parsing the mods for the same thing multiple times)
86
90
  def subject_names
87
91
  mods_ng_xml.subject.name_el
@@ -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.11'.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
 
@@ -238,6 +238,9 @@ describe "Subject fields (searchworks.rb)" do
238
238
  @smods_rec.from_str(@ng_mods_no_subject.to_s)
239
239
  expect(@smods_rec.subject_all_search).to eq []
240
240
  end
241
+ it "should contain top level <genre> element data" do
242
+ expect(@smods_rec.subject_all_search).to include(@genre)
243
+ end
241
244
  it "should not contain cartographic sub element" do
242
245
  expect(@smods_rec.subject_all_search).not_to include(@cart_coord)
243
246
  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: 3.3.9
4
+ version: 3.3.11
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-08-21 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.11
218
218
  signing_key:
219
219
  specification_version: 4
220
220
  summary: Stanford specific wrangling of MODS metadata