timetwister 0.0.1 → 0.1.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 +8 -8
- data/README.md +30 -5
- data/lib/timetwister/parser.rb +9 -2
- data/lib/timetwister/version.rb +1 -1
- data/lib/timetwister.rb +16 -8
- data/timetwister.gemspec +3 -2
- metadata +18 -4
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
YTMxMjc2YTZiZTdkMjE4YjE2MTk5YzUyNTVkNWM1MzRmMjI4ZGVjNg==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MWNkY2ViNzUxYWE0YzZhNWIxMTY2OWVhNjRiZjI1MDU0MWJlY2QxZQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
ZTgxNjhmM2ZmZTQ4NWJhOTQ1NjlhNjUzYmU4MGE3MTQ5MDc2NjhlZjQ3ZDg2
|
10
|
+
MmVhMGQ1OWVhMGEyMGIzMzVhMWY0MWE2ZThjZmE1ZjMwNjZhYzZiMzEyYmNk
|
11
|
+
ZTEzM2FlZGZjYzRiYzcwNzU4Y2MzNmUwMjVhZDM3OTQyOWUzODY=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
OGQxODUwNWM4NGE0M2IwNGFlOWIwZTQ5ZmNjNmNkZjQzYjJiODIxYTYyMjli
|
14
|
+
OTYwNWI5ZWVjMDI2NjMwMzk4Mjk4MDEwODNiZmFhNzZkY2JkNzRkZTZkYmY4
|
15
|
+
YTQ3NzdjODk4NjQ5ZWU3N2EwMmY5YTc5YTIyNDFhN2U1ZDFiYjc=
|
data/README.md
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
# Timetwister
|
2
2
|
|
3
|
-
|
3
|
+
A Chronic wrapper with improved date format parsing and fewer surprises.
|
4
|
+
|
5
|
+
Developed by the New York Public Library to transform freetext date metadata into machine-readable data.
|
4
6
|
|
5
7
|
## Installation
|
6
8
|
|
@@ -20,12 +22,35 @@ Or install it yourself as:
|
|
20
22
|
|
21
23
|
## Usage
|
22
24
|
|
23
|
-
|
25
|
+
Takes a date (or list of dates) as a string, and returns a list of hashes with parsed date data.
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
require 'timetwister'
|
29
|
+
Timetwister.parse("Jun 1898 - [July 4 1900]")
|
30
|
+
=> [{:original_string=>"Jun 1898 - July 4 1900", :index_dates=>[1898, 1899, 1900], :date_start=>"1898-06-01", :date_end=>"1900-07-04", :date_start_full=>"1898-06-01", :date_end_full=>"1900-07-04", :inclusive_range=>true, :certainty=>"inferred", :test_data=>"330"}]
|
31
|
+
```
|
32
|
+
|
33
|
+
Output explanation:
|
34
|
+
|
35
|
+
- `:original_string` is the original input
|
36
|
+
- `:index_dates` is an `Array` of each year encompassed by the provided date range
|
37
|
+
- `:date_start` and `:date_end` are ISO8601 representations of the input date, with no assumed values
|
38
|
+
- `:date_start_full` and `:date_end_full` are ISO8601 representations of the input date in YYYY-MM-DD format (using assumed values when needed)
|
39
|
+
- `:inclusive_range` is whether or not the input value is a range
|
40
|
+
- `:certainty` is the certainty of the provided date, based on use of flags and punctuation
|
24
41
|
|
25
42
|
## Contributing
|
26
43
|
|
27
44
|
1. Fork it ( https://github.com/[my-github-username]/timetwister/fork )
|
28
45
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
29
|
-
3.
|
30
|
-
4.
|
31
|
-
5.
|
46
|
+
3. Update specs to test for new features (`rspec`)
|
47
|
+
4. Commit your changes (`git commit -am 'Add some feature'`)
|
48
|
+
5. Push to the branch (`git push origin my-new-feature`)
|
49
|
+
6. Create a new Pull Request
|
50
|
+
|
51
|
+
## Contributors
|
52
|
+
|
53
|
+
- [Alex Duryee](https://github.com/alexduryee/)
|
54
|
+
- [Trevor Thornton](https://github.com/trevorthornton/)
|
55
|
+
- [Matt Miller](https://github.com/thisismattmiller/)
|
56
|
+
- [Stephen Schor](https://github.com/nodanaonlyzuul/)
|
data/lib/timetwister/parser.rb
CHANGED
@@ -2,13 +2,20 @@ require 'chronic'
|
|
2
2
|
|
3
3
|
class Parser
|
4
4
|
|
5
|
-
def self.string_to_dates(str,
|
5
|
+
def self.string_to_dates(str, options)
|
6
6
|
@string = str
|
7
|
-
@dates = hash
|
8
7
|
@options = options
|
9
8
|
|
9
|
+
@dates = { :original_string => str, :index_dates => [], :date_start => nil, :date_end => nil,
|
10
|
+
:date_start_full => nil, :date_end_full => nil, :inclusive_range => nil, :certainty => nil }
|
11
|
+
|
10
12
|
@regex_tokens = regex_tokens
|
11
13
|
|
14
|
+
# defensive checks against very malformed date strings
|
15
|
+
if str.include?('??')
|
16
|
+
return @dates
|
17
|
+
end
|
18
|
+
|
12
19
|
# perform this here, before the string gets purged of certainty indicators
|
13
20
|
@dates[:certainty] = return_certainty(@string)
|
14
21
|
|
data/lib/timetwister/version.rb
CHANGED
data/lib/timetwister.rb
CHANGED
@@ -5,16 +5,24 @@ module Timetwister
|
|
5
5
|
|
6
6
|
def self.parse(str, options={})
|
7
7
|
|
8
|
-
|
9
|
-
:date_start_full => nil, :date_end_full => nil, :inclusive_range => nil, :certainty => nil }
|
8
|
+
out = []
|
10
9
|
|
11
|
-
|
12
|
-
|
13
|
-
if str.include?('??')
|
14
|
-
return dates
|
15
|
-
end
|
10
|
+
str.split(';').each do |semi|
|
11
|
+
semi.split(' and ').each do |conj|
|
16
12
|
|
17
|
-
|
13
|
+
# check for dates of form "Month Day(-Day), Year" before splitting on commas
|
14
|
+
# (removes certainty markers as to not jam the regex)
|
15
|
+
if conj.gsub(/[\?\[\]]/, '').match(/[JFMASOND][A-Za-z]*\.?\s[0-9]{1,2}(\s?-[0-9]{1,2})?\,\s[0-9]{4}/)
|
16
|
+
out << Parser.string_to_dates(conj, options)
|
17
|
+
else
|
18
|
+
conj.split(',').each do |comma|
|
19
|
+
out << Parser.string_to_dates(comma, options)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
return out
|
18
26
|
|
19
27
|
end
|
20
28
|
end
|
data/timetwister.gemspec
CHANGED
@@ -8,8 +8,8 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.version = Timetwister::VERSION
|
9
9
|
spec.authors = ["Alex Duryee"]
|
10
10
|
spec.email = ["alexanderduryee@nypl.org"]
|
11
|
-
spec.summary = "Chronic wrapper to handle
|
12
|
-
spec.homepage = ""
|
11
|
+
spec.summary = "Chronic wrapper to handle common date formats"
|
12
|
+
spec.homepage = "http://github.com/alexduryee/timetwister"
|
13
13
|
spec.license = "MIT"
|
14
14
|
|
15
15
|
spec.files = `git ls-files -z`.split("\x0")
|
@@ -19,4 +19,5 @@ Gem::Specification.new do |spec|
|
|
19
19
|
|
20
20
|
spec.add_development_dependency "bundler", "~> 1.7"
|
21
21
|
spec.add_development_dependency "rake", "~> 10.0"
|
22
|
+
spec.add_runtime_dependency "chronic", "~> 0.10.2"
|
22
23
|
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.0
|
4
|
+
version: 0.1.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: 2015-12-
|
11
|
+
date: 2015-12-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - ~>
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: chronic
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.10.2
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.10.2
|
41
55
|
description:
|
42
56
|
email:
|
43
57
|
- alexanderduryee@nypl.org
|
@@ -54,7 +68,7 @@ files:
|
|
54
68
|
- lib/timetwister/parser.rb
|
55
69
|
- lib/timetwister/version.rb
|
56
70
|
- timetwister.gemspec
|
57
|
-
homepage:
|
71
|
+
homepage: http://github.com/alexduryee/timetwister
|
58
72
|
licenses:
|
59
73
|
- MIT
|
60
74
|
metadata: {}
|
@@ -77,5 +91,5 @@ rubyforge_project:
|
|
77
91
|
rubygems_version: 2.4.5
|
78
92
|
signing_key:
|
79
93
|
specification_version: 4
|
80
|
-
summary: Chronic wrapper to handle
|
94
|
+
summary: Chronic wrapper to handle common date formats
|
81
95
|
test_files: []
|