mods_display 0.7.0 → 0.7.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b98625a861414ce3c06cd365c9850454a50ccd83719124820a49f4fcb7ff107d
4
- data.tar.gz: e0c7ded47f3f3f38b821294f4bb9252e0fd7ffdb3fae837dc4da340bc225ab44
3
+ metadata.gz: f646ef8067a80ee0b0318f9f8c8d03ca5450c522772d5f514776aee4f03dae64
4
+ data.tar.gz: a04eb7333f672aba00e2a6cb0883ff580a027d23c97363becb11a634cf6b1661
5
5
  SHA512:
6
- metadata.gz: efd399144bc193f4db0bfd4b3185346dce1e8cc523fad133af38f61a19d2f41b42e8d05a4fad6ea77dab744eeba2b7727b2dfe911f34c49844ca94fd433320fa
7
- data.tar.gz: 121a7fa3ba9a0af4887fbc5fac992c95be7c19b888cb632fede718bb2796b1ceb783ce98f16e06de415e149b344584f6c4046dfa2f25c1bcc01823ade826ee46
6
+ metadata.gz: e5a0a38fac8e49e2e9fdc17c4560fd5cb0461f4c459eddf2981cfccc3e3a7df1cd1477acc9fae4537daf1cb269f439d5809799e09cc9487c8f813529612dbf1a
7
+ data.tar.gz: '09364c514c07be1ad564fb4f4325a7ad9f9abf031c08f140a7150119c6b2be6e14a8dd06a75e5aa19e3a31f096939df7ce4b87e493e5abbf7e4bdaadfd33daf8'
@@ -68,6 +68,8 @@ module ModsDisplay
68
68
  date_fields.map do |date_field|
69
69
  if date_is_w3cdtf?(date_field)
70
70
  process_w3cdtf_date(date_field)
71
+ elsif date_is_iso8601?(date_field)
72
+ process_iso8601_date(date_field)
71
73
  else
72
74
  date_field
73
75
  end
@@ -158,6 +160,10 @@ module ModsDisplay
158
160
  field_is_encoded?(date_field, 'w3cdtf')
159
161
  end
160
162
 
163
+ def date_is_iso8601?(date_field)
164
+ field_is_encoded?(date_field, 'iso8601')
165
+ end
166
+
161
167
  def process_w3cdtf_date(date_field)
162
168
  date_field = date_field.clone
163
169
  date_field.content = begin
@@ -174,6 +180,16 @@ module ModsDisplay
174
180
  date_field
175
181
  end
176
182
 
183
+ def process_iso8601_date(date_field)
184
+ date_field = date_field.clone
185
+ date_field.content = begin
186
+ Date.iso8601(date_field.text).strftime(@config.full_date_format)
187
+ rescue
188
+ date_field.content
189
+ end
190
+ date_field
191
+ end
192
+
177
193
  def dedup_dates(date_fields)
178
194
  date_text = date_fields.map { |d| normalize_date(d.text) }
179
195
  if date_text != date_text.uniq
@@ -1,3 +1,3 @@
1
1
  module ModsDisplay
2
- VERSION = '0.7.0'
2
+ VERSION = '0.7.1'
3
3
  end
@@ -43,6 +43,7 @@ describe ModsDisplay::Imprint do
43
43
  @imprint_date_range = Stanford::Mods::Record.new.from_str(imprint_date_range, false).origin_info
44
44
  @encoded_place = Stanford::Mods::Record.new.from_str(encoded_place, false).origin_info
45
45
  @encoded_dates = Stanford::Mods::Record.new.from_str(encoded_dates, false).origin_info
46
+ @iso8601_encoded_dates = Stanford::Mods::Record.new.from_str(iso8601_encoded_dates, false).origin_info
46
47
  @bad_dates = Stanford::Mods::Record.new.from_str(bad_dates, false).origin_info
47
48
  @invalid_dates = Stanford::Mods::Record.new.from_str(invalid_dates, false).origin_info
48
49
  @punctuation_imprint = Stanford::Mods::Record.new.from_str(punctuation_imprint_fixture, false).origin_info
@@ -209,6 +210,23 @@ describe ModsDisplay::Imprint do
209
210
  end.values).to eq(['July (2013)'])
210
211
  end
211
212
  end
213
+
214
+ describe 'iso8601' do
215
+ it 'handles full dates properly' do
216
+ fields = mods_display_imprint(@iso8601_encoded_dates).fields
217
+ expect(fields.length).to eq(2)
218
+ expect(fields.find do |field|
219
+ field.label == 'Date created:'
220
+ end.values).to eq(['November 14, 2013'])
221
+ end
222
+ it "should not try to handle dates we can't parse" do
223
+ fields = mods_display_imprint(@iso8601_encoded_dates).fields
224
+ expect(fields.length).to eq(2)
225
+ expect(fields.find do |field|
226
+ field.label == 'Date modified:'
227
+ end.values).to eq(['Jul. 22, 2013'])
228
+ end
229
+ end
212
230
  end
213
231
  describe 'bad dates' do
214
232
  it 'should ignore date values' do
@@ -280,6 +280,17 @@ module ImprintFixtures
280
280
  MODS
281
281
  end
282
282
 
283
+ def iso8601_encoded_dates
284
+ <<-MODS
285
+ <mods>
286
+ <originInfo>
287
+ <dateCreated encoding="iso8601">20131114161429</dateCreated>
288
+ <dateModified encoding="iso8601">Jul. 22, 2013</dateModified>
289
+ </originInfo>
290
+ </mods>
291
+ MODS
292
+ end
293
+
283
294
  def bad_dates
284
295
  <<-MODS
285
296
  <mods>
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mods_display
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jessie Keck
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-08-12 00:00:00.000000000 Z
11
+ date: 2019-09-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: stanford-mods