date_parser 0.1.21 → 0.1.31

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
  SHA1:
3
- metadata.gz: 67ebf3e486cf5ebd2af051c7bdebc2c779148d26
4
- data.tar.gz: 42fb0b6410dad47a5055b5b4eb88a4df2be97259
3
+ metadata.gz: b0ee93c7c95e25f759c7897e8d363c29d8feb31c
4
+ data.tar.gz: 547bcbd2acdcd45c8879fb43a531d7d007931054
5
5
  SHA512:
6
- metadata.gz: 6c805383acfb270d0966a6f0adecf474a614d3fe728c58c9370956ba9740ac3cb83250a425183d3ee7883dbacaf6dce4b7ce5365a211e0246ada87fe70fdfd03
7
- data.tar.gz: 780c64b2a755551709b562f8e315b5081c716787be2adbf8d7f000e96f44c5d559f81920e60527a0717599668a6f44e09539557c80c4a8c9cbf972dc5f7da0ef
6
+ metadata.gz: 1894089457ad01c0fbe40a79080baa435772dfa34c02fcc0ad2b5bfb0ae0dc11a7055b18163a5714b0dd26caaf351893258b7b406f6b98b6ec505aeee2deba61
7
+ data.tar.gz: 11b01f4f1749856d15ba0f301185565f3119cb271a9de1c242ee49e65e1b46c2283256f4e2ea0114b028aef92429179aec069965b5d047adc2ce7466010cf054
data/NEWS.md CHANGED
@@ -1,3 +1,8 @@
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
+
1
6
  # DateParser 0.1.2
2
7
  * New option: `parse_ambiguous_dates` flag, which determines whether or not some
3
8
  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 in a flexible way.
4
+ text.
5
5
 
6
6
  # Installation
7
7
  ```
8
8
  $ gem install date_parser
9
9
  ```
10
10
 
11
- # Usage
11
+ # Examples
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
- # Examples
91
+ # Usage
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
@@ -20,6 +20,8 @@ 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.
23
25
  #
24
26
  # ==== Options
25
27
  #
@@ -78,6 +80,11 @@ module DateParser
78
80
  parse_single_years = opts[:parse_single_years].nil? ? false : opts[:parse_single_years]
79
81
  parse_ambiguous_dates = opts[:parse_ambiguous_dates].nil? ? true : opts[:parse_ambiguous_dates]
80
82
 
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
+
81
88
  interpreted_dates = NaturalDateParsing::interpret_date(txt,
82
89
  creation_date,
83
90
  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
- # * +:parse_ambiguous_dates+ - Some phrases are not necessarily dates depending
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
- # * +:parse_ambiguous_dates+ - Some phrases are not necessarily dates depending
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.
@@ -31,6 +31,9 @@ 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.
34
37
  def Utils.delete_at_indices(array, range)
35
38
  first_val = range.first
36
39
  for _ in range do
@@ -39,4 +42,10 @@ module Utils
39
42
 
40
43
  return array
41
44
  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
42
51
  end
@@ -115,4 +115,54 @@ 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
118
168
  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.21
4
+ version: 0.1.31
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-07-29 00:00:00.000000000 Z
11
+ date: 2016-09-15 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 in a robust way.
14
+ language text.
15
15
  email: rynkwn@gmail.com
16
16
  executables: []
17
17
  extensions: []