timetwister 0.3.0 → 0.3.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 +4 -4
- data/.github/workflows/ruby.yml +35 -0
- data/lib/timetwister/utilities.rb +23 -5
- data/lib/timetwister/version.rb +1 -1
- data/spec/dates_spec.rb +68 -3
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 93fa574a2f0c2978b64b08db23b61cc6805f35ea2f9e94036e90ad010425d425
|
4
|
+
data.tar.gz: 10aee7dcc195da3eb77108113ed67d9eea87641782ae00216c3509adabf94a2e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 519d4485a0472394c83a3473d1d5720f2a6d7e6427d4411abb3643d971bc19e199b0ca9f38a0d9bb53aaaaa4b24430eb131e0455fd7a61edf87c67e43b7f41b4
|
7
|
+
data.tar.gz: 383890f74d7b161718b5b8e7e8c445e6847740bda00e46439c40ac2ae5e89b8dca75128816d963be23747dfe4a19613cac8da9031c13c854fa91916fa030d3d4
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# This workflow uses actions that are not certified by GitHub.
|
2
|
+
# They are provided by a third-party and are governed by
|
3
|
+
# separate terms of service, privacy policy, and support
|
4
|
+
# documentation.
|
5
|
+
# This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
|
6
|
+
# For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
|
7
|
+
|
8
|
+
name: Ruby
|
9
|
+
|
10
|
+
on:
|
11
|
+
push:
|
12
|
+
branches: [ master ]
|
13
|
+
pull_request:
|
14
|
+
branches: [ master ]
|
15
|
+
|
16
|
+
jobs:
|
17
|
+
test:
|
18
|
+
|
19
|
+
runs-on: ubuntu-latest
|
20
|
+
strategy:
|
21
|
+
matrix:
|
22
|
+
ruby-version: ['2.6', '2.7', '3.0']
|
23
|
+
|
24
|
+
steps:
|
25
|
+
- uses: actions/checkout@v2
|
26
|
+
- name: Set up Ruby
|
27
|
+
# To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
|
28
|
+
# change this to (see https://github.com/ruby/setup-ruby#versioning):
|
29
|
+
# uses: ruby/setup-ruby@v1
|
30
|
+
uses: ruby/setup-ruby@473e4d8fe5dd94ee328fdfca9f8c9c7afc9dae5e
|
31
|
+
with:
|
32
|
+
ruby-version: ${{ matrix.ruby-version }}
|
33
|
+
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
|
34
|
+
- name: Run tests
|
35
|
+
run: bundle exec rspec
|
@@ -236,11 +236,7 @@ class Utilities
|
|
236
236
|
]
|
237
237
|
|
238
238
|
# transform seasons to months
|
239
|
-
string
|
240
|
-
string.gsub!(/[Ss]pring/, " March 20 - June 21 ")
|
241
|
-
string.gsub!(/[Ss]ummer/, " June 21 - September 23 ")
|
242
|
-
string.gsub!(/[Aa]utumn/, " September 23 - December 22 ")
|
243
|
-
string.gsub!(/[Ff]all/, " September 23 - December 22 ")
|
239
|
+
string = replace_seasons(string)
|
244
240
|
|
245
241
|
# remove days of the week
|
246
242
|
dow = [/[Ss]unday,?\s+/, /[Mm]onday,?\s+/, /[Tt]uesday,?\s+/, /[Ww]ednesday,?\s+/, /[Tt]hursday,?\s+/, /[Ff]riday,?\s+/, /[Ss]aturday,?\s+/]
|
@@ -258,6 +254,28 @@ class Utilities
|
|
258
254
|
return string
|
259
255
|
end
|
260
256
|
|
257
|
+
def self.replace_seasons(string)
|
258
|
+
seasons = { 'win[^\s]*' => ['January 1', 'March 20'],
|
259
|
+
'spr[^\s]*' => ['March 20', 'June 21'],
|
260
|
+
'sum[^\s]*' => ['June 21', 'September 23'],
|
261
|
+
'aut[^\s]*' => ['September 23', 'December 31'],
|
262
|
+
'fal[^\s]*' => ['September 23', 'December 31']}
|
263
|
+
|
264
|
+
# if we're working with a range, we need to be a little careful, so that we don't create sub-ranges in a string
|
265
|
+
is_range = string.match(/[^-]+?-[^-]+?/)
|
266
|
+
|
267
|
+
seasons.each do |season, dates|
|
268
|
+
regex = Regexp.new(season, Regexp::IGNORECASE)
|
269
|
+
|
270
|
+
# is the season the beginning or the end of a range?
|
271
|
+
new_date = (is_range ? (string.match(Regexp.new(season + '.+?-', Regexp::IGNORECASE)) ? dates[0] : dates[1]) : dates.join(' - '))
|
272
|
+
|
273
|
+
string = string.gsub(regex, new_date)
|
274
|
+
end
|
275
|
+
|
276
|
+
return string
|
277
|
+
end
|
278
|
+
|
261
279
|
# Removes the first 4-digit number found in the string and returns it
|
262
280
|
def self.extract_year(string)
|
263
281
|
year = string.match(/\d{4}/).to_s
|
data/lib/timetwister/version.rb
CHANGED
data/spec/dates_spec.rb
CHANGED
@@ -344,7 +344,7 @@ describe Timetwister do
|
|
344
344
|
end
|
345
345
|
end
|
346
346
|
|
347
|
-
it "parses seasons" do
|
347
|
+
it "parses single seasons" do
|
348
348
|
date = Timetwister.parse("Winter 1776")
|
349
349
|
expect(date[0][:date_start]).to eq("1776-01-01")
|
350
350
|
expect(date[0][:date_start_full]).to eq("1776-01-01")
|
@@ -354,6 +354,15 @@ describe Timetwister do
|
|
354
354
|
expect(date[0][:index_dates]).to eq([1776])
|
355
355
|
expect(date[0][:test_data]).to eq("310")
|
356
356
|
|
357
|
+
date = Timetwister.parse("win. 1776")
|
358
|
+
expect(date[0][:date_start]).to eq("1776-01-01")
|
359
|
+
expect(date[0][:date_start_full]).to eq("1776-01-01")
|
360
|
+
expect(date[0][:date_end]).to eq("1776-03-20")
|
361
|
+
expect(date[0][:date_end_full]).to eq("1776-03-20")
|
362
|
+
expect(date[0][:inclusive_range]).to eq(true)
|
363
|
+
expect(date[0][:index_dates]).to eq([1776])
|
364
|
+
expect(date[0][:test_data]).to eq("310")
|
365
|
+
|
357
366
|
date = Timetwister.parse("1776 Spring")
|
358
367
|
expect(date[0][:date_start]).to eq("1776-03-20")
|
359
368
|
expect(date[0][:date_start_full]).to eq("1776-03-20")
|
@@ -363,6 +372,15 @@ describe Timetwister do
|
|
363
372
|
expect(date[0][:index_dates]).to eq([1776])
|
364
373
|
expect(date[0][:test_data]).to eq("310")
|
365
374
|
|
375
|
+
date = Timetwister.parse("1776 Spr")
|
376
|
+
expect(date[0][:date_start]).to eq("1776-03-20")
|
377
|
+
expect(date[0][:date_start_full]).to eq("1776-03-20")
|
378
|
+
expect(date[0][:date_end]).to eq("1776-06-21")
|
379
|
+
expect(date[0][:date_end_full]).to eq("1776-06-21")
|
380
|
+
expect(date[0][:inclusive_range]).to eq(true)
|
381
|
+
expect(date[0][:index_dates]).to eq([1776])
|
382
|
+
expect(date[0][:test_data]).to eq("310")
|
383
|
+
|
366
384
|
date = Timetwister.parse("1776 Summer")
|
367
385
|
expect(date[0][:date_start]).to eq("1776-06-21")
|
368
386
|
expect(date[0][:date_start_full]).to eq("1776-06-21")
|
@@ -372,16 +390,63 @@ describe Timetwister do
|
|
372
390
|
expect(date[0][:index_dates]).to eq([1776])
|
373
391
|
expect(date[0][:test_data]).to eq("310")
|
374
392
|
|
393
|
+
date = Timetwister.parse("1776 Summ")
|
394
|
+
expect(date[0][:date_start]).to eq("1776-06-21")
|
395
|
+
expect(date[0][:date_start_full]).to eq("1776-06-21")
|
396
|
+
expect(date[0][:date_end]).to eq("1776-09-23")
|
397
|
+
expect(date[0][:date_end_full]).to eq("1776-09-23")
|
398
|
+
expect(date[0][:inclusive_range]).to eq(true)
|
399
|
+
expect(date[0][:index_dates]).to eq([1776])
|
400
|
+
expect(date[0][:test_data]).to eq("310")
|
401
|
+
|
375
402
|
date = Timetwister.parse("Fall 1776")
|
376
403
|
expect(date[0][:date_start]).to eq("1776-09-23")
|
377
404
|
expect(date[0][:date_start_full]).to eq("1776-09-23")
|
378
|
-
expect(date[0][:date_end]).to eq("1776-12-
|
379
|
-
expect(date[0][:date_end_full]).to eq("1776-12-
|
405
|
+
expect(date[0][:date_end]).to eq("1776-12-31")
|
406
|
+
expect(date[0][:date_end_full]).to eq("1776-12-31")
|
407
|
+
expect(date[0][:inclusive_range]).to eq(true)
|
408
|
+
expect(date[0][:index_dates]).to eq([1776])
|
409
|
+
expect(date[0][:test_data]).to eq("310")
|
410
|
+
|
411
|
+
date = Timetwister.parse("Autumn 1776")
|
412
|
+
expect(date[0][:date_start]).to eq("1776-09-23")
|
413
|
+
expect(date[0][:date_start_full]).to eq("1776-09-23")
|
414
|
+
expect(date[0][:date_end]).to eq("1776-12-31")
|
415
|
+
expect(date[0][:date_end_full]).to eq("1776-12-31")
|
416
|
+
expect(date[0][:inclusive_range]).to eq(true)
|
417
|
+
expect(date[0][:index_dates]).to eq([1776])
|
418
|
+
expect(date[0][:test_data]).to eq("310")
|
419
|
+
|
420
|
+
date = Timetwister.parse("Aut. 1776")
|
421
|
+
expect(date[0][:date_start]).to eq("1776-09-23")
|
422
|
+
expect(date[0][:date_start_full]).to eq("1776-09-23")
|
423
|
+
expect(date[0][:date_end]).to eq("1776-12-31")
|
424
|
+
expect(date[0][:date_end_full]).to eq("1776-12-31")
|
380
425
|
expect(date[0][:inclusive_range]).to eq(true)
|
381
426
|
expect(date[0][:index_dates]).to eq([1776])
|
382
427
|
expect(date[0][:test_data]).to eq("310")
|
383
428
|
end
|
384
429
|
|
430
|
+
it "parses ranges of seasons" do
|
431
|
+
date = Timetwister.parse("Winter 1776 - Spring 1777")
|
432
|
+
expect(date[0][:date_start]).to eq("1776-01-01")
|
433
|
+
expect(date[0][:date_start_full]).to eq("1776-01-01")
|
434
|
+
expect(date[0][:date_end]).to eq("1777-06-21")
|
435
|
+
expect(date[0][:date_end_full]).to eq("1777-06-21")
|
436
|
+
expect(date[0][:inclusive_range]).to eq(true)
|
437
|
+
expect(date[0][:index_dates]).to eq([1776, 1777])
|
438
|
+
expect(date[0][:test_data]).to eq("80")
|
439
|
+
|
440
|
+
date = Timetwister.parse("1777 Spring - 1778 Summer")
|
441
|
+
expect(date[0][:date_start]).to eq("1777-03-20")
|
442
|
+
expect(date[0][:date_start_full]).to eq("1777-03-20")
|
443
|
+
expect(date[0][:date_end]).to eq("1778-09-23")
|
444
|
+
expect(date[0][:date_end_full]).to eq("1778-09-23")
|
445
|
+
expect(date[0][:inclusive_range]).to eq(true)
|
446
|
+
expect(date[0][:index_dates]).to eq([1777, 1778])
|
447
|
+
expect(date[0][:test_data]).to eq("80")
|
448
|
+
end
|
449
|
+
|
385
450
|
it "parses dates with punctuation" do
|
386
451
|
forms = ["July 4 1776?", "July 4 1776 [?]", "July 4? 1776", "?July 4 1776?", "[July] 4 1776?"]
|
387
452
|
forms.each do |f|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: timetwister
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alex Duryee
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-06-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -46,6 +46,7 @@ executables:
|
|
46
46
|
extensions: []
|
47
47
|
extra_rdoc_files: []
|
48
48
|
files:
|
49
|
+
- ".github/workflows/ruby.yml"
|
49
50
|
- ".gitignore"
|
50
51
|
- ".travis.yml"
|
51
52
|
- Gemfile
|