tickle 1.0.2 → 1.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 +4 -4
- data/CHANGES.md +9 -2
- data/Gemfile +0 -1
- data/Rakefile +0 -2
- data/lib/tickle.rb +15 -17
- data/lib/tickle/tickle.rb +0 -2
- data/lib/tickle/version.rb +1 -1
- data/test/test_parsing.rb +8 -8
- data/tickle.gemspec +1 -0
- metadata +16 -3
- data/lib/numerizer/numerizer.rb +0 -103
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f37559d98569337ef293a7dab47aff50bbf79ddc
|
4
|
+
data.tar.gz: ae5ab433c8e9561b83ce453c25ca1bebb957f024
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c46c9d0305c4c0ed9bc669998c05951e551a2c96d10a117a49fcf72e13d3dc7afce702c47c68f2262d5e3ed3d29fa1fc5730a4b284a08bbd2f6348675fae781f
|
7
|
+
data.tar.gz: 305f4b9f2c78624d5d98e71d13563eb6892e1b2c88e9cae0be7f990ec763b8ab345952684b32f41197c14d4087a142cac54207464dee39653e983e14f32deace
|
data/CHANGES.md
CHANGED
@@ -1,14 +1,21 @@
|
|
1
1
|
# CH CH CH CH CHANGES! #
|
2
2
|
|
3
|
+
## Wednesday the 22nd of February 2017, v1.1.0 ##
|
3
4
|
|
4
|
-
|
5
|
+
* Numerizer duplication removed. Thanks to https://github.com/bjonord.
|
6
|
+
* Some very minor changes to the project, no other code changes.
|
7
|
+
|
8
|
+
----
|
9
|
+
|
10
|
+
|
11
|
+
## Monday the 11th of November 2015, v1.0.2 ##
|
5
12
|
|
6
13
|
* Shoulda and simplecov aren't runtime dependencies, fixed that in the gemfile.
|
7
14
|
* Got the version number right this time ;-)
|
8
15
|
|
9
16
|
----
|
10
17
|
|
11
|
-
## Monday the 11th of November, v1.0.1 ##
|
18
|
+
## Monday the 11th of November 2015, v1.0.1 ##
|
12
19
|
|
13
20
|
* Moved library to new maintainer [https://github.com/yb66/tickle](@yb66)
|
14
21
|
* Moved library to [http://semver.org/](semver).
|
data/Gemfile
CHANGED
data/Rakefile
CHANGED
data/lib/tickle.rb
CHANGED
@@ -16,10 +16,8 @@ require 'chronic'
|
|
16
16
|
require 'tickle/tickle'
|
17
17
|
require 'tickle/handler'
|
18
18
|
require 'tickle/repeater'
|
19
|
-
require 'numerizer/numerizer'
|
20
19
|
|
21
20
|
module Tickle #:nodoc:
|
22
|
-
VERSION = "0.1.7"
|
23
21
|
|
24
22
|
def self.debug=(val); @debug = val; end
|
25
23
|
|
@@ -49,20 +47,20 @@ class Date #:nodoc:
|
|
49
47
|
amount ||= 1
|
50
48
|
case attr
|
51
49
|
when :day then
|
52
|
-
Date.civil(self.year, self.month, self.day
|
50
|
+
Date.civil(self.year, self.month, self.day).next_day(amount)
|
53
51
|
when :wday then
|
54
52
|
amount = Date::ABBR_DAYNAMES.index(amount) if amount.is_a?(String)
|
55
53
|
raise Exception, "specified day of week invalid. Use #{Date::ABBR_DAYNAMES}" unless amount
|
56
54
|
diff = (amount > self.wday) ? (amount - self.wday) : (7 - (self.wday - amount))
|
57
|
-
Date.civil(self.year, self.month, self.day
|
55
|
+
Date.civil(self.year, self.month, self.day).next_day(diff)
|
58
56
|
when :week then
|
59
|
-
Date.civil(self.year, self.month, self.day
|
57
|
+
Date.civil(self.year, self.month, self.day).next_day(7*amount)
|
60
58
|
when :month then
|
61
|
-
Date.civil(self.year, self.month
|
59
|
+
Date.civil(self.year, self.month, self.day).next_month(amount)
|
62
60
|
when :year then
|
63
|
-
Date.civil(self.year
|
61
|
+
Date.civil(self.year, self.month, self.day).next_year(amount)
|
64
62
|
else
|
65
|
-
|
63
|
+
raise Exception, "type \"#{attr}\" not supported."
|
66
64
|
end
|
67
65
|
end
|
68
66
|
end
|
@@ -72,27 +70,27 @@ class Time #:nodoc:
|
|
72
70
|
amount ||= 1
|
73
71
|
case attr
|
74
72
|
when :sec then
|
75
|
-
Time.local(self.year, self.month, self.day, self.hour, self.min, self.sec + amount
|
73
|
+
Time.local(self.year, self.month, self.day, self.hour, self.min, self.sec) + amount
|
76
74
|
when :min then
|
77
|
-
Time.local(self.year, self.month, self.day, self.hour, self.min
|
75
|
+
Time.local(self.year, self.month, self.day, self.hour, self.min, self.sec) + (amount * 60)
|
78
76
|
when :hour then
|
79
|
-
Time.local(self.year, self.month, self.day, self.hour
|
77
|
+
Time.local(self.year, self.month, self.day, self.hour, self.min, self.sec) + (amount * 60 * 60)
|
80
78
|
when :day then
|
81
|
-
Time.local(self.year, self.month, self.day
|
79
|
+
Time.local(self.year, self.month, self.day, self.hour, self.min, self.sec) + (amount * 60 * 60 * 24)
|
82
80
|
when :wday then
|
83
81
|
amount = Time::RFC2822_DAY_NAME.index(amount) if amount.is_a?(String)
|
84
82
|
raise Exception, "specified day of week invalid. Use #{Time::RFC2822_DAY_NAME}" unless amount
|
85
83
|
diff = (amount > self.wday) ? (amount - self.wday) : (7 - (self.wday - amount))
|
86
|
-
|
84
|
+
DateTime.civil(self.year, self.month, self.day, self.hour, self.min, self.sec, self.zone).next_day(diff)
|
87
85
|
when :week then
|
88
|
-
|
86
|
+
DateTime.civil(self.year, self.month, self.day, self.hour, self.min, self.sec, self.zone).next_day(amount * 7)
|
89
87
|
when :month then
|
90
|
-
|
88
|
+
DateTime.civil(self.year, self.month, self.day, self.hour, self.min, self.sec, self.zone).next_month(amount)
|
91
89
|
when :year then
|
92
|
-
|
90
|
+
DateTime.civil(self.year, self.month, self.day, self.hour, self.min, self.sec, self.zone).next_year(amount)
|
93
91
|
else
|
94
92
|
raise Exception, "type \"#{attr}\" not supported."
|
95
|
-
end
|
93
|
+
end.to_time.localtime
|
96
94
|
end
|
97
95
|
end
|
98
96
|
|
data/lib/tickle/tickle.rb
CHANGED
@@ -19,8 +19,6 @@
|
|
19
19
|
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
20
|
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
21
|
|
22
|
-
require_relative "../numerizer/numerizer.rb"
|
23
|
-
|
24
22
|
module Tickle
|
25
23
|
class << self
|
26
24
|
# == Configuration options
|
data/lib/tickle/version.rb
CHANGED
data/test/test_parsing.rb
CHANGED
@@ -165,30 +165,30 @@ class TestParsing < Test::Unit::TestCase
|
|
165
165
|
|
166
166
|
def test_argument_validation
|
167
167
|
assert_raise(Tickle::InvalidArgumentException) do
|
168
|
-
|
168
|
+
Tickle.parse("may 27", :today => 'something odd')
|
169
169
|
end
|
170
170
|
|
171
171
|
assert_raise(Tickle::InvalidArgumentException) do
|
172
|
-
|
172
|
+
Tickle.parse("may 27", :foo => :bar)
|
173
173
|
end
|
174
174
|
|
175
175
|
assert_raise(Tickle::InvalidArgumentException) do
|
176
|
-
|
176
|
+
Tickle.parse(nil)
|
177
177
|
end
|
178
178
|
|
179
179
|
assert_raise(Tickle::InvalidDateExpression) do
|
180
180
|
past_date = Date.civil(Date.today.year, Date.today.month, Date.today.day - 1)
|
181
|
-
|
181
|
+
Tickle.parse("every other day", {:start => past_date})
|
182
182
|
end
|
183
183
|
|
184
184
|
assert_raise(Tickle::InvalidDateExpression) do
|
185
|
-
start_date = Date.civil(Date.today.year, Date.today.month
|
186
|
-
end_date = Date.civil(Date.today.year, Date.today.month
|
187
|
-
|
185
|
+
start_date = Date.civil(Date.today.year, Date.today.month).next_day(10)
|
186
|
+
end_date = Date.civil(Date.today.year, Date.today.month).next_day(5)
|
187
|
+
Tickle.parse("every other day", :start => start_date, :until => end_date)
|
188
188
|
end
|
189
189
|
|
190
190
|
assert_raise(Tickle::InvalidDateExpression) do
|
191
|
-
end_date = Date.civil(Date.today.year, Date.today.month
|
191
|
+
end_date = Date.civil(Date.today.year, Date.today.month, Date.today.day).next_month(2)
|
192
192
|
parse_now('every 3 months', {:until => end_date})
|
193
193
|
end
|
194
194
|
end
|
data/tickle.gemspec
CHANGED
@@ -23,6 +23,7 @@ Gem::Specification.new do |s|
|
|
23
23
|
s.add_dependency "chronic", "~> 0.2.3"
|
24
24
|
s.add_development_dependency "shoulda", "~> 2.10.3"
|
25
25
|
s.add_development_dependency "simplecov"
|
26
|
+
s.add_development_dependency "test-unit"
|
26
27
|
|
27
28
|
s.add_development_dependency "bundler", "~> 1.2"
|
28
29
|
s.add_development_dependency "rake"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tickle
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joshua Lippiner
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2017-02-22 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: chronic
|
@@ -53,6 +53,20 @@ dependencies:
|
|
53
53
|
- - ">="
|
54
54
|
- !ruby/object:Gem::Version
|
55
55
|
version: '0'
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: test-unit
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
56
70
|
- !ruby/object:Gem::Dependency
|
57
71
|
name: bundler
|
58
72
|
requirement: !ruby/object:Gem::Requirement
|
@@ -127,7 +141,6 @@ files:
|
|
127
141
|
- SCENARIOS.rdoc
|
128
142
|
- examples.rb
|
129
143
|
- git-flow-version
|
130
|
-
- lib/numerizer/numerizer.rb
|
131
144
|
- lib/tickle.rb
|
132
145
|
- lib/tickle/handler.rb
|
133
146
|
- lib/tickle/repeater.rb
|
data/lib/numerizer/numerizer.rb
DELETED
@@ -1,103 +0,0 @@
|
|
1
|
-
require 'strscan'
|
2
|
-
|
3
|
-
class Numerizer
|
4
|
-
|
5
|
-
DIRECT_NUMS = [
|
6
|
-
['eleven', '11'],
|
7
|
-
['twelve', '12'],
|
8
|
-
['thirteen', '13'],
|
9
|
-
['fourteen', '14'],
|
10
|
-
['fifteen', '15'],
|
11
|
-
['sixteen', '16'],
|
12
|
-
['seventeen', '17'],
|
13
|
-
['eighteen', '18'],
|
14
|
-
['nineteen', '19'],
|
15
|
-
['ninteen', '19'], # Common mis-spelling
|
16
|
-
['zero', '0'],
|
17
|
-
['one', '1'],
|
18
|
-
['two', '2'],
|
19
|
-
['three', '3'],
|
20
|
-
['four(\W|$)', '4\1'], # The weird regex is so that it matches four but not fourty
|
21
|
-
['five', '5'],
|
22
|
-
['six(\W|$)', '6\1'],
|
23
|
-
['seven(\W|$)', '7\1'],
|
24
|
-
['eight(\W|$)', '8\1'],
|
25
|
-
['nine(\W|$)', '9\1'],
|
26
|
-
['ten', '10'],
|
27
|
-
['\ba[\b^$]', '1'] # doesn't make sense for an 'a' at the end to be a 1
|
28
|
-
]
|
29
|
-
|
30
|
-
TEN_PREFIXES = [ ['twenty', 20],
|
31
|
-
['thirty', 30],
|
32
|
-
['fourty', 40],
|
33
|
-
['fifty', 50],
|
34
|
-
['sixty', 60],
|
35
|
-
['seventy', 70],
|
36
|
-
['eighty', 80],
|
37
|
-
['ninety', 90]
|
38
|
-
]
|
39
|
-
|
40
|
-
BIG_PREFIXES = [ ['hundred', 100],
|
41
|
-
['thousand', 1000],
|
42
|
-
['million', 1_000_000],
|
43
|
-
['billion', 1_000_000_000],
|
44
|
-
['trillion', 1_000_000_000_000],
|
45
|
-
]
|
46
|
-
|
47
|
-
class << self
|
48
|
-
def numerize(string)
|
49
|
-
string = string.dup
|
50
|
-
|
51
|
-
# preprocess
|
52
|
-
string.gsub!(/ +|([^\d])-([^d])/, '\1 \2') # will mutilate hyphenated-words but shouldn't matter for date extraction
|
53
|
-
string.gsub!(/a half/, 'haAlf') # take the 'a' out so it doesn't turn into a 1, save the half for the end
|
54
|
-
|
55
|
-
# easy/direct replacements
|
56
|
-
|
57
|
-
DIRECT_NUMS.each do |dn|
|
58
|
-
string.gsub!(/#{dn[0]}/i, dn[1])
|
59
|
-
end
|
60
|
-
|
61
|
-
# ten, twenty, etc.
|
62
|
-
|
63
|
-
TEN_PREFIXES.each do |tp|
|
64
|
-
string.gsub!(/(?:#{tp[0]})( *\d(?=[^\d]|$))*/i) { (tp[1] + $1.to_i).to_s }
|
65
|
-
end
|
66
|
-
|
67
|
-
# hundreds, thousands, millions, etc.
|
68
|
-
|
69
|
-
BIG_PREFIXES.each do |bp|
|
70
|
-
string.gsub!(/(\d*) *#{bp[0]}/i) { (bp[1] * $1.to_i).to_s}
|
71
|
-
andition(string)
|
72
|
-
#combine_numbers(string) # Should to be more efficient way to do this
|
73
|
-
end
|
74
|
-
|
75
|
-
# fractional addition
|
76
|
-
# I'm not combining this with the previous block as using float addition complicates the strings
|
77
|
-
# (with extraneous .0's and such )
|
78
|
-
string.gsub!(/(\d+)(?: | and |-)*haAlf/i) { ($1.to_f + 0.5).to_s }
|
79
|
-
|
80
|
-
string
|
81
|
-
end
|
82
|
-
|
83
|
-
private
|
84
|
-
def andition(string)
|
85
|
-
sc = StringScanner.new(string)
|
86
|
-
while(sc.scan_until(/(\d+)( | and )(\d+)(?=[^\w]|$)/i))
|
87
|
-
if sc[2] =~ /and/ || sc[1].size > sc[3].size
|
88
|
-
string[(sc.pos - sc.matched_size)..(sc.pos-1)] = (sc[1].to_i + sc[3].to_i).to_s
|
89
|
-
sc.reset
|
90
|
-
end
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
|
-
# def combine_numbers(string)
|
95
|
-
# sc = StringScanner.new(string)
|
96
|
-
# while(sc.scan_until(/(\d+)(?: | and |-)(\d+)(?=[^\w]|$)/i))
|
97
|
-
# string[(sc.pos - sc.matched_size)..(sc.pos-1)] = (sc[1].to_i + sc[2].to_i).to_s
|
98
|
-
# sc.reset
|
99
|
-
# end
|
100
|
-
# end
|
101
|
-
|
102
|
-
end
|
103
|
-
end
|