stanford-mods 2.4.1 → 2.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/stanford-mods/imprint.rb +37 -0
- data/lib/stanford-mods/version.rb +1 -1
- data/spec/imprint_spec.rb +19 -0
- data/stanford-mods.gemspec +1 -1
- metadata +4 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 59b15047f00caeb2284b28a22050e1656a8237ad
|
4
|
+
data.tar.gz: 43e5403241eeac0a90a17ec06fc2d80f4588a39e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5c6ca8c2716fd12e10d5097569c47e02fab1cb6d9bf83bd02568239498432596ec7ef4b8ddafb2e8045a846bc56e6fd47804319f61e2c175db8427aedeb4eafa
|
7
|
+
data.tar.gz: 1c25481b485b3ff62288a2577241c5198d839c5d361e03b33560ab7de54f719e6e6b97f9dd31452a823af122dbed6998932a421ff54d127382e990c34396457d
|
@@ -37,8 +37,45 @@ module Stanford
|
|
37
37
|
imprint_statements.join('; ') if imprint_statements.present?
|
38
38
|
end
|
39
39
|
|
40
|
+
# @return Array<Integer> an array of publication years for the resource
|
41
|
+
def publication_date_for_slider
|
42
|
+
@originInfo_ng_nodeset.map do |origin_info_node|
|
43
|
+
|
44
|
+
date_elements = if origin_info_node.as_object.first.key_dates.any?
|
45
|
+
origin_info_node.as_object.first.key_dates.map(&:as_object).map(&:first)
|
46
|
+
else
|
47
|
+
date_field_keys.map do |date_field|
|
48
|
+
next unless origin_info_node.respond_to?(date_field)
|
49
|
+
date_elements = origin_info_node.send(date_field)
|
50
|
+
date_elements.map(&:as_object).map(&:first) if date_elements.any?
|
51
|
+
end.first
|
52
|
+
end
|
53
|
+
|
54
|
+
if date_elements.nil? || date_elements.none?
|
55
|
+
[]
|
56
|
+
elsif date_elements.find(&:start?) && date_elements.find(&:end?)
|
57
|
+
start_date = date_elements.find(&:start?)
|
58
|
+
end_date = date_elements.find(&:end?)
|
59
|
+
|
60
|
+
(start_date.as_range.min.year..end_date.as_range.max.year).to_a
|
61
|
+
elsif date_elements.find(&:start?)
|
62
|
+
start_date = date_elements.find(&:start?)
|
63
|
+
|
64
|
+
(start_date.as_range.min.year..Time.now.year).to_a
|
65
|
+
elsif date_elements.one?
|
66
|
+
date_elements.first.to_a.map(&:year)
|
67
|
+
else
|
68
|
+
date_elements.map { |v| v.to_a.map(&:year) }.flatten
|
69
|
+
end
|
70
|
+
end.flatten
|
71
|
+
end
|
72
|
+
|
40
73
|
private
|
41
74
|
|
75
|
+
def extract_year(el)
|
76
|
+
DateParsing.year_int_from_date_str(el.text)
|
77
|
+
end
|
78
|
+
|
42
79
|
def compact_and_join_with_delimiter(values, delimiter)
|
43
80
|
compact_values = values.compact.reject { |v| v.strip.empty? }
|
44
81
|
return compact_values.join(delimiter) if compact_values.length == 1 ||
|
data/spec/imprint_spec.rb
CHANGED
@@ -9,6 +9,25 @@ describe Stanford::Mods::Imprint do
|
|
9
9
|
let(:mods_origin_info_end_str) { '</originInfo></mods>' }
|
10
10
|
|
11
11
|
describe 'date processing' do
|
12
|
+
describe '#publication_date_for_slider' do
|
13
|
+
{
|
14
|
+
'' => [],
|
15
|
+
'<dateIssued>1957</dateIssued>' => [1957],
|
16
|
+
'<dateIssued>195u</dateIssued>' => (1950..1959).to_a,
|
17
|
+
'<dateCreated keyDate="yes">1964</dateCreated><dateIssued>195u</dateIssued>' => [1964],
|
18
|
+
'<dateIssued>1964</dateIssued><dateCreated>195u</dateCreated>' => [1964],
|
19
|
+
'<dateIssued point="start">195u</dateIssued><dateIssued point="end">1964</dateIssued>' => (1950..1964).to_a,
|
20
|
+
'<dateIssued>1964</dateIssued><dateIssued>195u</dateIssued>' => [1964] + (1950..1959).to_a
|
21
|
+
}.each do |example, expected|
|
22
|
+
it 'works' do
|
23
|
+
smods_rec.from_str("#{mods_origin_info_start_str}
|
24
|
+
#{example}
|
25
|
+
#{mods_origin_info_end_str}")
|
26
|
+
imprint = stanford_mods_imprint(smods_rec)
|
27
|
+
expect(imprint.publication_date_for_slider).to eq expected
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
12
31
|
describe 'bad dates' do
|
13
32
|
it 'ignores bad date values' do
|
14
33
|
smods_rec.from_str(mods_origin_info_start_str +
|
data/stanford-mods.gemspec
CHANGED
@@ -16,7 +16,7 @@ Gem::Specification.new do |gem|
|
|
16
16
|
gem.test_files = gem.files.grep(%r{^spec/})
|
17
17
|
gem.require_paths = ["lib"]
|
18
18
|
|
19
|
-
gem.add_dependency 'mods', '~> 2.
|
19
|
+
gem.add_dependency 'mods', '~> 2.2'
|
20
20
|
# active_support for .ordinalize, eg. 1 -> 1st, 2 -> 2nd for centuries
|
21
21
|
gem.add_dependency 'activesupport'
|
22
22
|
|
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: 2.
|
4
|
+
version: 2.5.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: 2017-
|
12
|
+
date: 2017-12-05 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: mods
|
@@ -17,20 +17,14 @@ dependencies:
|
|
17
17
|
requirements:
|
18
18
|
- - "~>"
|
19
19
|
- !ruby/object:Gem::Version
|
20
|
-
version: '2.
|
21
|
-
- - ">="
|
22
|
-
- !ruby/object:Gem::Version
|
23
|
-
version: 2.0.2
|
20
|
+
version: '2.2'
|
24
21
|
type: :runtime
|
25
22
|
prerelease: false
|
26
23
|
version_requirements: !ruby/object:Gem::Requirement
|
27
24
|
requirements:
|
28
25
|
- - "~>"
|
29
26
|
- !ruby/object:Gem::Version
|
30
|
-
version: '2.
|
31
|
-
- - ">="
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: 2.0.2
|
27
|
+
version: '2.2'
|
34
28
|
- !ruby/object:Gem::Dependency
|
35
29
|
name: activesupport
|
36
30
|
requirement: !ruby/object:Gem::Requirement
|