timetwister 0.2.9 → 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: eafc8587cbe011c71e42a9cb69d71a7764a3af6a5c79a6c95581a367e88ef08e
4
- data.tar.gz: c12f67bf757e69213161ace32bb25ad821fb748c67bd3c8df270047eb8a57279
3
+ metadata.gz: 9ab710e9b2068bc7945925206c7033765c9ab6c8c03a0dec28e8271e1888d322
4
+ data.tar.gz: 8d37aba572fc43b434b5da1febff19e77d12155a744787aaada2a98d2748a262
5
5
  SHA512:
6
- metadata.gz: e93b630a3d2ed379d4868a62961914d89e7484874dcb588c17adac0bbadb6a54922f08b0f62f10f9f772acd4188cc8c3f316ec65918fd7bf1c72d620edb9b36f
7
- data.tar.gz: bba5c953b7d5616415ce5316b2ba3b0079443387a19b4b562a4a57ccbdd3b18540e70878d66f61eb475a72a523cbcf441a7cd9b2eed5c1f03ee02fe0520bb935
6
+ metadata.gz: a8ab93f028d366e5dfd48a25c72768796eac9d586b6d03e698eb7e58022b37d9862577a7cccd5425f9749091167481e17d20cbe1197904bb6209602e262eae94
7
+ data.tar.gz: 780ee2a7bb4575a385dcbf4d0a417e671f1da7d700115a547391546303ae189b7b96301268fecfeb8c16d088aca883cd100672f51167c8b7366651df665b8c0b
@@ -56,17 +56,7 @@ class Parser
56
56
  if c[:proc]
57
57
  # clone string to avoid changing it via in-place methods used in Procs
58
58
  work_string = @string.clone
59
-
60
- # using a begin/rescue to catch dates that Date.parse errors on
61
- begin
62
- c[:proc].call(work_string, c[:arg])
63
-
64
- # ArgumentError for pre-2.7.0 DateTime errors,
65
- # Date::Error for 2.7.0 and later
66
- rescue ArgumentError || Date::Error
67
- @dates = { :original_string => @string, :index_dates => [], :keydate => nil, :keydate_z => nil, :date_start => nil, :date_end => nil,
68
- :date_start_full => nil, :date_end_full => nil, :inclusive_range => nil, :certainty => nil }
69
- end
59
+ c[:proc].call(work_string, c[:arg])
70
60
  end
71
61
  break
72
62
  end
@@ -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.9"
2
+ VERSION = "0.3.0"
3
3
  end
data/spec/dates_spec.rb CHANGED
@@ -46,6 +46,7 @@ describe Timetwister do
46
46
  end
47
47
 
48
48
  it "parses ranges of full dates" do
49
+
49
50
  forms = ["July 4 1776 - March 1 1789", "4 July 1776 - 1 March 1789", "1776 July 4 - 1789 March 1", "1776 4 July - 1789 1 March", "1776 4 July to 1789 1 March"]
50
51
  forms.each do |f|
51
52
  date = Timetwister.parse(f)
@@ -343,7 +344,7 @@ describe Timetwister do
343
344
  end
344
345
  end
345
346
 
346
- it "parses single seasons" do
347
+ it "parses seasons" do
347
348
  date = Timetwister.parse("Winter 1776")
348
349
  expect(date[0][:date_start]).to eq("1776-01-01")
349
350
  expect(date[0][:date_start_full]).to eq("1776-01-01")
@@ -353,15 +354,6 @@ describe Timetwister do
353
354
  expect(date[0][:index_dates]).to eq([1776])
354
355
  expect(date[0][:test_data]).to eq("310")
355
356
 
356
- date = Timetwister.parse("win. 1776")
357
- expect(date[0][:date_start]).to eq("1776-01-01")
358
- expect(date[0][:date_start_full]).to eq("1776-01-01")
359
- expect(date[0][:date_end]).to eq("1776-03-20")
360
- expect(date[0][:date_end_full]).to eq("1776-03-20")
361
- expect(date[0][:inclusive_range]).to eq(true)
362
- expect(date[0][:index_dates]).to eq([1776])
363
- expect(date[0][:test_data]).to eq("310")
364
-
365
357
  date = Timetwister.parse("1776 Spring")
366
358
  expect(date[0][:date_start]).to eq("1776-03-20")
367
359
  expect(date[0][:date_start_full]).to eq("1776-03-20")
@@ -371,15 +363,6 @@ describe Timetwister do
371
363
  expect(date[0][:index_dates]).to eq([1776])
372
364
  expect(date[0][:test_data]).to eq("310")
373
365
 
374
- date = Timetwister.parse("1776 Spr")
375
- expect(date[0][:date_start]).to eq("1776-03-20")
376
- expect(date[0][:date_start_full]).to eq("1776-03-20")
377
- expect(date[0][:date_end]).to eq("1776-06-21")
378
- expect(date[0][:date_end_full]).to eq("1776-06-21")
379
- expect(date[0][:inclusive_range]).to eq(true)
380
- expect(date[0][:index_dates]).to eq([1776])
381
- expect(date[0][:test_data]).to eq("310")
382
-
383
366
  date = Timetwister.parse("1776 Summer")
384
367
  expect(date[0][:date_start]).to eq("1776-06-21")
385
368
  expect(date[0][:date_start_full]).to eq("1776-06-21")
@@ -389,61 +372,14 @@ describe Timetwister do
389
372
  expect(date[0][:index_dates]).to eq([1776])
390
373
  expect(date[0][:test_data]).to eq("310")
391
374
 
392
- date = Timetwister.parse("1776 Summ")
393
- expect(date[0][:date_start]).to eq("1776-06-21")
394
- expect(date[0][:date_start_full]).to eq("1776-06-21")
395
- expect(date[0][:date_end]).to eq("1776-09-23")
396
- expect(date[0][:date_end_full]).to eq("1776-09-23")
397
- expect(date[0][:inclusive_range]).to eq(true)
398
- expect(date[0][:index_dates]).to eq([1776])
399
- expect(date[0][:test_data]).to eq("310")
400
-
401
375
  date = Timetwister.parse("Fall 1776")
402
376
  expect(date[0][:date_start]).to eq("1776-09-23")
403
377
  expect(date[0][:date_start_full]).to eq("1776-09-23")
404
- expect(date[0][:date_end]).to eq("1776-12-31")
405
- expect(date[0][:date_end_full]).to eq("1776-12-31")
406
- expect(date[0][:inclusive_range]).to eq(true)
407
- expect(date[0][:index_dates]).to eq([1776])
408
- expect(date[0][:test_data]).to eq("310")
409
-
410
- date = Timetwister.parse("Autumn 1776")
411
- expect(date[0][:date_start]).to eq("1776-09-23")
412
- expect(date[0][:date_start_full]).to eq("1776-09-23")
413
- expect(date[0][:date_end]).to eq("1776-12-31")
414
- 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")
415
380
  expect(date[0][:inclusive_range]).to eq(true)
416
381
  expect(date[0][:index_dates]).to eq([1776])
417
382
  expect(date[0][:test_data]).to eq("310")
418
-
419
- date = Timetwister.parse("Aut. 1776")
420
- expect(date[0][:date_start]).to eq("1776-09-23")
421
- expect(date[0][:date_start_full]).to eq("1776-09-23")
422
- expect(date[0][:date_end]).to eq("1776-12-31")
423
- expect(date[0][:date_end_full]).to eq("1776-12-31")
424
- expect(date[0][:inclusive_range]).to eq(true)
425
- expect(date[0][:index_dates]).to eq([1776])
426
- expect(date[0][:test_data]).to eq("310")
427
- end
428
-
429
- it "parses ranges of seasons" do
430
- date = Timetwister.parse("Winter 1776 - Spring 1777")
431
- expect(date[0][:date_start]).to eq("1776-01-01")
432
- expect(date[0][:date_start_full]).to eq("1776-01-01")
433
- expect(date[0][:date_end]).to eq("1777-06-21")
434
- expect(date[0][:date_end_full]).to eq("1777-06-21")
435
- expect(date[0][:inclusive_range]).to eq(true)
436
- expect(date[0][:index_dates]).to eq([1776, 1777])
437
- expect(date[0][:test_data]).to eq("80")
438
-
439
- date = Timetwister.parse("1777 Spring - 1778 Summer")
440
- expect(date[0][:date_start]).to eq("1777-03-20")
441
- expect(date[0][:date_start_full]).to eq("1777-03-20")
442
- expect(date[0][:date_end]).to eq("1778-09-23")
443
- expect(date[0][:date_end_full]).to eq("1778-09-23")
444
- expect(date[0][:inclusive_range]).to eq(true)
445
- expect(date[0][:index_dates]).to eq([1777, 1778])
446
- expect(date[0][:test_data]).to eq("80")
447
383
  end
448
384
 
449
385
  it "parses dates with punctuation" do
@@ -571,62 +507,6 @@ describe Timetwister do
571
507
  end
572
508
  end
573
509
 
574
- it "DOES NOT parse nonexistent dates" do
575
- date = Timetwister.parse('1776 September 31')
576
- expect(date[0][:date_start]).to eq(nil)
577
- expect(date[0][:date_start_full]).to eq(nil)
578
- expect(date[0][:date_end]).to eq(nil)
579
- expect(date[0][:date_end_full]).to eq(nil)
580
- expect(date[0][:inclusive_range]).to eq(nil)
581
- expect(date[0][:index_dates]).to eq([])
582
- expect(date[0][:test_data]).to eq(nil)
583
-
584
- date = Timetwister.parse('1776-11-31')
585
- expect(date[0][:date_start]).to eq(nil)
586
- expect(date[0][:date_start_full]).to eq(nil)
587
- expect(date[0][:date_end]).to eq(nil)
588
- expect(date[0][:date_end_full]).to eq(nil)
589
- expect(date[0][:inclusive_range]).to eq(nil)
590
- expect(date[0][:index_dates]).to eq([])
591
- expect(date[0][:test_data]).to eq(nil)
592
-
593
- date = Timetwister.parse('1776-11-00')
594
- expect(date[0][:date_start]).to eq(nil)
595
- expect(date[0][:date_start_full]).to eq(nil)
596
- expect(date[0][:date_end]).to eq(nil)
597
- expect(date[0][:date_end_full]).to eq(nil)
598
- expect(date[0][:inclusive_range]).to eq(nil)
599
- expect(date[0][:index_dates]).to eq([])
600
- expect(date[0][:test_data]).to eq(nil)
601
-
602
- date = Timetwister.parse('1776 whatever 31')
603
- expect(date[0][:date_start]).to eq(nil)
604
- expect(date[0][:date_start_full]).to eq(nil)
605
- expect(date[0][:date_end]).to eq(nil)
606
- expect(date[0][:date_end_full]).to eq(nil)
607
- expect(date[0][:inclusive_range]).to eq(nil)
608
- expect(date[0][:index_dates]).to eq([])
609
- expect(date[0][:test_data]).to eq(nil)
610
-
611
- date = Timetwister.parse('1776 sometime 72 - december 42 1999')
612
- expect(date[0][:date_start]).to eq(nil)
613
- expect(date[0][:date_start_full]).to eq(nil)
614
- expect(date[0][:date_end]).to eq(nil)
615
- expect(date[0][:date_end_full]).to eq(nil)
616
- expect(date[0][:inclusive_range]).to eq(nil)
617
- expect(date[0][:index_dates]).to eq([])
618
- expect(date[0][:test_data]).to eq(nil)
619
-
620
- date = Timetwister.parse('just absolute garbage')
621
- expect(date[0][:date_start]).to eq(nil)
622
- expect(date[0][:date_start_full]).to eq(nil)
623
- expect(date[0][:date_end]).to eq(nil)
624
- expect(date[0][:date_end_full]).to eq(nil)
625
- expect(date[0][:inclusive_range]).to eq(nil)
626
- expect(date[0][:index_dates]).to eq([])
627
- expect(date[0][:test_data]).to eq(nil)
628
- end
629
-
630
510
  it "parses lists of years" do
631
511
  date = Timetwister.parse("1776, 1789, 1812")
632
512
  expect(date[0][:date_start]).to eq("1776")
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.9
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: 2023-03-06 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.3', '2.4', '2.5', '2.6', '2.7', '3.0']
23
-
24
- steps:
25
- - uses: actions/checkout@v3
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@v1
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