timetwister 0.2.4 → 0.2.5

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,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- YzlhYjlmZjMwMmI3YjBhNjBiYTYxYTZjMzk0OGQwZGRjYjUwODNkZg==
4
+ NWIyYWYyOTcwYzY4NjExNWI0NmE1MTU0NjE4ZjMwZWU1MTI4OTlmOA==
5
5
  data.tar.gz: !binary |-
6
- ZjliMGUwMTQyY2IzZmQzY2E0NjJjMmM2YjViMGM4N2M2MmNiYTdhOQ==
6
+ OGZlMDhlYTg3MzZkY2Y2Mzg4YTY0ZmZjMWQ3MjI1ODliNTU3OTA2Mg==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- YTJmOWZjOTdmNWYwNDY0OWNjZGE5OWQ1NThhMjk5YzgwNjI5NDgyYjE3NTU2
10
- N2QxMjkxN2ViMmQ0OGI1YWNjMDczM2EzNTQ3MmUyOTg5MzIyNTJmYmNjYWU2
11
- Mjc5M2I3MThjZjc5N2ZlNzFhMTc5YmVkNTJlZjZlNjViZjk3ODQ=
9
+ NzZlOTJkMjY1Njc4Mjc4Yzg5YmU1YTM1YTIyYTA5OTlhOTU3NWU0YTQ1Y2Nj
10
+ MTQ2MWRkMDJhYTQzODA1YTNkYTA3MDYxZTQyYzczNjIyYThjNTM0MzYzOGQ4
11
+ NGM4NWY4NjE3MGY1MWI1YTA5Y2NmNmY2ZDAzZTFkMmNjMWY4OTk=
12
12
  data.tar.gz: !binary |-
13
- Y2EyMWI3N2I0MWM3YTRiYzdiYjFhMWQ4NTU2OGVmZmU3ZDRmY2E2MWE3ZTI3
14
- NTY0MzZhZGI4NzNhMDc0ZWE2MGRkOTRhMDEzNTAyYzFmNTNhZTA5NWY5NjA3
15
- MGYzMTg1ZTZmZDgwNzY5NzBhZDk4Zjg3MmNiYzVhOGFhMjNkNmI=
13
+ YWI3ZWI3ZmE4M2NkNTBjNjQ4YjA5ZTgyNWUyOWI2YTU3MzU0MTY3YzgyNTE3
14
+ YjM4ZTRhZjJmMTZkNjg0YWIxMmJjZWM2Yzg1MGVkMWRmMmJkZjA3ZjcxZmFj
15
+ Yzc2NDQxYWNmZGQ0YmY1NjJiMWVkM2EwNzE1NjA1ZjUwMzI5MTE=
@@ -296,8 +296,6 @@ class Parser
296
296
  }
297
297
 
298
298
 
299
-
300
-
301
299
  # 19--, 18--, 18--?, etc.
302
300
  match_replace << {
303
301
  :match => "(#{r[:circa]})?[1-2][0-9]\-{2}",
@@ -352,6 +350,13 @@ class Parser
352
350
  :id => 350
353
351
  }
354
352
 
353
+ # 19th century
354
+ match_replace << {
355
+ :match => "(#{r[:decade_qualifier]})?\s?[0-2]?[0-9]\s[Cc][Ee][Nn][Tt][Uu][Rr][Yy]",
356
+ :proc => proc_century_with_qualifiers,
357
+ :id => 360
358
+ }
359
+
355
360
  match_replace
356
361
  end
357
362
 
@@ -487,6 +492,34 @@ class Parser
487
492
  end
488
493
  end
489
494
 
495
+ # mid 19th century
496
+ def self.proc_century_with_qualifiers
497
+ proc = Proc.new do |string|
498
+ century = string.match(/[0-9]{2}/).to_s
499
+
500
+ if string.match(/[Ee]arly/)
501
+ range_start = '00'
502
+ range_end = '40'
503
+ elsif string.match(/[Mm]id(dle)?/)
504
+ range_start = '30'
505
+ range_end = '80'
506
+ elsif string.match(/[Ll]ate/)
507
+ range_start = '70'
508
+ range_end = '00'
509
+ else
510
+ range_start = '00'
511
+ range_end = '99'
512
+ end
513
+
514
+ century_start = (century + range_start).to_i - 100
515
+ century_end = (century + range_end).to_i - 100
516
+
517
+ @dates[:index_dates] = (century_start..century_end).to_a
518
+ @dates[:inclusive_range] = true
519
+ process_year_range()
520
+ end
521
+ end
522
+
490
523
  # early 1990s
491
524
  def self.proc_decade_s_qualified
492
525
  proc = Proc.new do |string|
@@ -792,7 +825,7 @@ class Parser
792
825
  month_date_start = datetime_start.strftime('%Y-%m')
793
826
  month_date_end = datetime_end.strftime('%Y-%m-%d')
794
827
  end
795
- end
828
+ end
796
829
 
797
830
  if datetime_start && datetime_end
798
831
  process_date_range(datetime_start,datetime_end)
@@ -821,7 +854,6 @@ class Parser
821
854
  end
822
855
  end
823
856
 
824
-
825
857
  # Transform full date strings into parsed datetime objects
826
858
  # e.g. "September 9, 1999" -> datetime
827
859
  def self.full_date_single_to_datetime(string)
@@ -291,7 +291,7 @@ class Utilities
291
291
  # circa, ca. - also matches 'c.', which is actually 'copyright', but is still not something we need to deal with
292
292
  :circa => '\s*[Cc](irc)?a?\.?\s*',
293
293
  # early, late, mid-
294
- :decade_qualifier => '([Ee]arly)|([Mm]id)|([Ll]ate)\-?',
294
+ :decade_qualifier => '(([Ee]arly)|([Mm]id)|([Ll]ate))\-?',
295
295
  # 06-16-1972, 6-16-1972
296
296
  :numeric_date_us => '(0?1)|(0?2)|(0?3)|(0?4)|(0?5)|(0?6)|(0?7)|(0?8)|(0?9)|1[0-2][\-\/](([0-2]?[0-9])|3[01])[\-\/])?[12][0-9]{3}',
297
297
  # 1972-06-16
@@ -1,3 +1,3 @@
1
1
  module Timetwister
2
- VERSION = "0.2.4"
2
+ VERSION = "0.2.5"
3
3
  end
data/lib/timetwister.rb CHANGED
@@ -4,29 +4,28 @@ require "timetwister/utilities"
4
4
 
5
5
  module Timetwister
6
6
 
7
- def self.parse(str, options={})
8
-
9
- out = []
10
- str = rearrange_conjunctions(str)
11
-
12
- str.split(';').each do |semi|
13
- semi.split(/\sand\s|\s\&\s/i).each do |conj|
14
-
15
- # check for dates of form "Month Day(-Day), Year" before splitting on commas
16
- # (removes certainty markers as to not jam the regex)
17
- if Utilities.replace_ordinals(conj).gsub(/[\?\[\]]/, '').match(/[a-z]*\.?\s[0-9]{1,2}(\s?-[0-9]{1,2})?\,\s[0-9]{4}/i)
18
- out << Parser.string_to_dates(conj, options)
19
- else
20
- conj.split(',').each do |comma|
21
- out << Parser.string_to_dates(comma, options)
22
- end
23
- end
24
- end
7
+ def self.parse(str, options={})
8
+
9
+ out = []
10
+ str = rearrange_conjunctions(str)
11
+
12
+ str.split(';').each do |semi|
13
+ semi.split(/\sand\s|\s\&\s/i).each do |conj|
14
+
15
+ # check for dates of form "Month Day(-Day), Year" before splitting on commas
16
+ # (removes certainty markers as to not jam the regex)
17
+ if Utilities.replace_ordinals(conj).gsub(/[\?\[\]]/, '').match(/[a-z]*\.?\s[0-9]{1,2}(\s?-[0-9]{1,2})?\,\s[0-9]{4}/i)
18
+ out << Parser.string_to_dates(conj, options)
19
+ else
20
+ conj.split(',').each do |comma|
21
+ out << Parser.string_to_dates(comma, options)
22
+ end
23
+ end
25
24
  end
25
+ end
26
26
 
27
- return out
28
-
29
- end
27
+ return out
28
+ end
30
29
 
31
30
  # sometimes years are considered implicit in complex dates
32
31
  # e.g. "1900 January & February"
data/spec/dates_spec.rb CHANGED
@@ -647,7 +647,21 @@ describe Timetwister do
647
647
  expect(date[1][:index_dates]).to eq([1776])
648
648
  expect(date[1][:test_data]).to eq("220")
649
649
  end
650
+ end
650
651
 
652
+ it "parses dates with qualifiers, certainty, and very vague dates" do
653
+ date = Timetwister.parse("ca. mid 19th century")
654
+ expect(date[0][:date_start]).to eq("1830")
655
+ expect(date[0][:date_start_full]).to eq("1830-01-01")
656
+ expect(date[0][:date_end]).to eq("1880")
657
+ expect(date[0][:date_end_full]).to eq("1880-12-31")
651
658
  end
652
659
 
660
+ it "parses centuries" do
661
+ date = Timetwister.parse("17th century")
662
+ expect(date[0][:date_start]).to eq('1600')
663
+ expect(date[0][:date_start_full]).to eq("1600-01-01")
664
+ expect(date[0][:date_end]).to eq("1699")
665
+ expect(date[0][:date_end_full]).to eq("1699-12-31")
666
+ end
653
667
  end
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.4
4
+ version: 0.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Duryee
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-01-08 00:00:00.000000000 Z
11
+ date: 2016-04-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler