timetwister 0.2.8 → 0.3.0

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: ca0d0c30070a1b30680aed8c91ab6950f8b3673395546605f1dc1c0bb72954ea
4
- data.tar.gz: cee49664ffebe37b764217e1cfd212c12b6e364928425a913598e3dc44eb6903
3
+ metadata.gz: 9ab710e9b2068bc7945925206c7033765c9ab6c8c03a0dec28e8271e1888d322
4
+ data.tar.gz: 8d37aba572fc43b434b5da1febff19e77d12155a744787aaada2a98d2748a262
5
5
  SHA512:
6
- metadata.gz: 897f1be9853d0c9ebe3800519b507f346bb0c78c265fe2b4d42a0d75e148faf9ccc919fe1d0e14bdc9b73676f39ecdd5ceb156dfaf25904f4d62c0e7fb89bd29
7
- data.tar.gz: 867c87500e0011732f9c863fff5bb03ee78080f42ad63755d541ed07bc6d72ed83e41c8f490e3323498ff82dd5421cbd989360be66b96520d0dba21b2a0cc1ba
6
+ metadata.gz: a8ab93f028d366e5dfd48a25c72768796eac9d586b6d03e698eb7e58022b37d9862577a7cccd5425f9749091167481e17d20cbe1197904bb6209602e262eae94
7
+ data.tar.gz: 780ee2a7bb4575a385dcbf4d0a417e671f1da7d700115a547391546303ae189b7b96301268fecfeb8c16d088aca883cd100672f51167c8b7366651df665b8c0b
@@ -236,7 +236,11 @@ class Utilities
236
236
  ]
237
237
 
238
238
  # transform seasons to months
239
- string = replace_seasons(string)
239
+ string.gsub!(/[Ww]inter/, " January 1 - March 20 ")
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 ")
240
244
 
241
245
  # remove days of the week
242
246
  dow = [/[Ss]unday,?\s+/, /[Mm]onday,?\s+/, /[Tt]uesday,?\s+/, /[Ww]ednesday,?\s+/, /[Tt]hursday,?\s+/, /[Ff]riday,?\s+/, /[Ss]aturday,?\s+/]
@@ -254,28 +258,6 @@ class Utilities
254
258
  return string
255
259
  end
256
260
 
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
-
279
261
  # Removes the first 4-digit number found in the string and returns it
280
262
  def self.extract_year(string)
281
263
  year = string.match(/\d{4}/).to_s
@@ -1,3 +1,3 @@
1
1
  module Timetwister
2
- VERSION = "0.2.8"
2
+ VERSION = "0.3.0"
3
3
  end
data/spec/dates_spec.rb CHANGED
@@ -344,7 +344,7 @@ describe Timetwister do
344
344
  end
345
345
  end
346
346
 
347
- it "parses single seasons" do
347
+ it "parses 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,15 +354,6 @@ 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
-
366
357
  date = Timetwister.parse("1776 Spring")
367
358
  expect(date[0][:date_start]).to eq("1776-03-20")
368
359
  expect(date[0][:date_start_full]).to eq("1776-03-20")
@@ -372,15 +363,6 @@ describe Timetwister do
372
363
  expect(date[0][:index_dates]).to eq([1776])
373
364
  expect(date[0][:test_data]).to eq("310")
374
365
 
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
-
384
366
  date = Timetwister.parse("1776 Summer")
385
367
  expect(date[0][:date_start]).to eq("1776-06-21")
386
368
  expect(date[0][:date_start_full]).to eq("1776-06-21")
@@ -390,63 +372,16 @@ describe Timetwister do
390
372
  expect(date[0][:index_dates]).to eq([1776])
391
373
  expect(date[0][:test_data]).to eq("310")
392
374
 
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
-
402
375
  date = Timetwister.parse("Fall 1776")
403
376
  expect(date[0][:date_start]).to eq("1776-09-23")
404
377
  expect(date[0][:date_start_full]).to eq("1776-09-23")
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")
378
+ expect(date[0][:date_end]).to eq("1776-12-22")
379
+ expect(date[0][:date_end_full]).to eq("1776-12-22")
425
380
  expect(date[0][:inclusive_range]).to eq(true)
426
381
  expect(date[0][:index_dates]).to eq([1776])
427
382
  expect(date[0][:test_data]).to eq("310")
428
383
  end
429
384
 
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
-
450
385
  it "parses dates with punctuation" do
451
386
  forms = ["July 4 1776?", "July 4 1776 [?]", "July 4? 1776", "?July 4 1776?", "[July] 4 1776?"]
452
387
  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.2.8
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Duryee
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-06-24 00:00:00.000000000 Z
11
+ date: 2021-10-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -46,7 +46,6 @@ executables:
46
46
  extensions: []
47
47
  extra_rdoc_files: []
48
48
  files:
49
- - ".github/workflows/ruby.yml"
50
49
  - ".gitignore"
51
50
  - ".travis.yml"
52
51
  - Gemfile
@@ -1,35 +0,0 @@
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