date_parser 0.1.3 → 0.1.21
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/NEWS.md +0 -5
- data/README.md +3 -3
- data/lib/date_parser.rb +0 -7
- data/lib/date_parser/natural_date_parsing.rb +2 -2
- data/lib/date_parser/utils.rb +0 -9
- data/lib/spec/date_parser_spec.rb +0 -50
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 67ebf3e486cf5ebd2af051c7bdebc2c779148d26
|
4
|
+
data.tar.gz: 42fb0b6410dad47a5055b5b4eb88a4df2be97259
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6c805383acfb270d0966a6f0adecf474a614d3fe728c58c9370956ba9740ac3cb83250a425183d3ee7883dbacaf6dce4b7ce5365a211e0246ada87fe70fdfd03
|
7
|
+
data.tar.gz: 780c64b2a755551709b562f8e315b5081c716787be2adbf8d7f000e96f44c5d559f81920e60527a0717599668a6f44e09539557c80c4a8c9cbf972dc5f7da0ef
|
data/NEWS.md
CHANGED
@@ -1,8 +1,3 @@
|
|
1
|
-
# DateParser 0.1.3
|
2
|
-
* New internal checks to avoid ambiguous behavior.
|
3
|
-
+ Notably: creation_date is enforced to be a descendent of the Date class.
|
4
|
-
* New tests to ensure that the program fails when unexpected types are passed in.
|
5
|
-
|
6
1
|
# DateParser 0.1.2
|
7
2
|
* New option: `parse_ambiguous_dates` flag, which determines whether or not some
|
8
3
|
looser phrases are considered dates.
|
data/README.md
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
# DateParser
|
2
2
|
|
3
3
|
DateParser is a simple, fast, effective way of parsing dates from natural language
|
4
|
-
text.
|
4
|
+
text in a flexible way.
|
5
5
|
|
6
6
|
# Installation
|
7
7
|
```
|
8
8
|
$ gem install date_parser
|
9
9
|
```
|
10
10
|
|
11
|
-
#
|
11
|
+
# Usage
|
12
12
|
```ruby
|
13
13
|
require 'date_parser'
|
14
14
|
|
@@ -88,7 +88,7 @@ DateParser::parse("No dates here",
|
|
88
88
|
#=> [#<Date: 2016-01-01 ((2457389j,0s,0n),+0s,2299161j)>]
|
89
89
|
```
|
90
90
|
|
91
|
-
#
|
91
|
+
# Examples
|
92
92
|
|
93
93
|
DateParser has just one function: `parse(txt, creation_date, opts)`, which
|
94
94
|
always returns an array with Date elements parsed from the text. If DateParser
|
data/lib/date_parser.rb
CHANGED
@@ -20,8 +20,6 @@ module DateParser
|
|
20
20
|
#
|
21
21
|
# * +creation_date+ - A Date object of when the text was created or released.
|
22
22
|
# Defaults to nil, but if provided can make returned dates more accurate.
|
23
|
-
# This is intentionally checked to be a Date object, as other data types
|
24
|
-
# may cause unforeseen behavior.
|
25
23
|
#
|
26
24
|
# ==== Options
|
27
25
|
#
|
@@ -80,11 +78,6 @@ module DateParser
|
|
80
78
|
parse_single_years = opts[:parse_single_years].nil? ? false : opts[:parse_single_years]
|
81
79
|
parse_ambiguous_dates = opts[:parse_ambiguous_dates].nil? ? true : opts[:parse_ambiguous_dates]
|
82
80
|
|
83
|
-
if ! Utils::descended_from?(creation_date, Date)
|
84
|
-
raise ArgumentError, "creation_date must be a descendent of the Date class." +
|
85
|
-
"Otherwise, ambiguous behavior may result."
|
86
|
-
end
|
87
|
-
|
88
81
|
interpreted_dates = NaturalDateParsing::interpret_date(txt,
|
89
82
|
creation_date,
|
90
83
|
parse_single_years,
|
@@ -84,7 +84,7 @@ module NaturalDateParsing
|
|
84
84
|
# * +parse_single_years+ - A boolean. If true, we interpret single numbers as
|
85
85
|
# years. This is a very broad assumption, and so defaults to false.
|
86
86
|
#
|
87
|
-
# *
|
87
|
+
# * +:parse_ambiguous_dates+ - Some phrases are not necessarily dates depending
|
88
88
|
# on context. For example "1st" may not refer to
|
89
89
|
# the 1st of a month. This option toggles whether or not those
|
90
90
|
# phrases are considered dates. Defaults to true.
|
@@ -202,7 +202,7 @@ module NaturalDateParsing
|
|
202
202
|
# * +parse_single_years+ - A boolean. If true, we interpret single numbers as
|
203
203
|
# years. This is a very broad assumption, and so defaults to false.
|
204
204
|
#
|
205
|
-
# *
|
205
|
+
# * +:parse_ambiguous_dates+ - Some phrases are not necessarily dates depending
|
206
206
|
# on context. For example "1st" may not refer to
|
207
207
|
# the 1st of a month. This option toggles whether or not those
|
208
208
|
# phrases are considered dates. Defaults to true.
|
data/lib/date_parser/utils.rb
CHANGED
@@ -31,9 +31,6 @@ module Utils
|
|
31
31
|
end
|
32
32
|
|
33
33
|
# Performs delete_at for a range of integers
|
34
|
-
#
|
35
|
-
# Assumes that the integers in range are contiguous, and sorted in ascending
|
36
|
-
# order.
|
37
34
|
def Utils.delete_at_indices(array, range)
|
38
35
|
first_val = range.first
|
39
36
|
for _ in range do
|
@@ -42,10 +39,4 @@ module Utils
|
|
42
39
|
|
43
40
|
return array
|
44
41
|
end
|
45
|
-
|
46
|
-
# Checks to see if an object is descended from an ancestor (or is the ancestor)
|
47
|
-
# nil_accepted is a flag that checks
|
48
|
-
def Utils.descended_from?(obj, ancestor, nil_accepted = true)
|
49
|
-
return obj.nil? ? nil_accepted : obj.class.ancestors.include?(ancestor)
|
50
|
-
end
|
51
42
|
end
|
@@ -115,54 +115,4 @@ describe DateParser do
|
|
115
115
|
end
|
116
116
|
end
|
117
117
|
end
|
118
|
-
|
119
|
-
#########################################################
|
120
|
-
##
|
121
|
-
## Type Testing
|
122
|
-
##
|
123
|
-
|
124
|
-
#########################
|
125
|
-
## Negative Tests
|
126
|
-
##
|
127
|
-
describe ".parse" do
|
128
|
-
context "Passing an int for creation_date" do
|
129
|
-
text = "2012-02-12"
|
130
|
-
creation_date = 12
|
131
|
-
|
132
|
-
it "Raises an exception" do
|
133
|
-
expect { DateParser::parse(text, creation_date) }.to raise_exception(ArgumentError)
|
134
|
-
end
|
135
|
-
end
|
136
|
-
|
137
|
-
context "Passing a String for creation_date" do
|
138
|
-
text = "2012-02-12"
|
139
|
-
creation_date = "Test"
|
140
|
-
|
141
|
-
it "Raises an exception" do
|
142
|
-
expect { DateParser::parse(text, creation_date) }.to raise_exception(ArgumentError)
|
143
|
-
end
|
144
|
-
end
|
145
|
-
|
146
|
-
context "Passing a Time for creation_date" do
|
147
|
-
text = "2012-02-12"
|
148
|
-
creation_date = Time.at(0)
|
149
|
-
|
150
|
-
it "Raises an exception" do
|
151
|
-
expect { DateParser::parse(text, creation_date) }.to raise_exception(ArgumentError)
|
152
|
-
end
|
153
|
-
end
|
154
|
-
|
155
|
-
#########################
|
156
|
-
## Positive Tests
|
157
|
-
##
|
158
|
-
context "Passing in a DateTime object for creation_date" do
|
159
|
-
text = "Something something something march 4 something something"
|
160
|
-
creation_date = DateTime.parse("Jan 1, 2004")
|
161
|
-
answer = [Date.parse("March 4, 2004")]
|
162
|
-
|
163
|
-
it "Does not raise an exception, and produces the correct answer" do
|
164
|
-
expect(DateParser::parse(text, creation_date)).to eql(answer)
|
165
|
-
end
|
166
|
-
end
|
167
|
-
end
|
168
118
|
end
|
metadata
CHANGED
@@ -1,17 +1,17 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: date_parser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.21
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryan Kwon
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-07-29 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: DateParser is a simple, fast, and effective way to parse dates from natural
|
14
|
-
language text.
|
14
|
+
language text in a robust way.
|
15
15
|
email: rynkwn@gmail.com
|
16
16
|
executables: []
|
17
17
|
extensions: []
|