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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2e7c98a6545c1b7e583d69309c0d76be4f91266c
4
- data.tar.gz: 0039b3ba223bf9082d7a290dd71b16395c5fe023
3
+ metadata.gz: f37559d98569337ef293a7dab47aff50bbf79ddc
4
+ data.tar.gz: ae5ab433c8e9561b83ce453c25ca1bebb957f024
5
5
  SHA512:
6
- metadata.gz: a9dc27b51edc3cc4d3cd5d9df5dfbcbdbd6f249317a0bc3771238caa852fa079ed0f4873fd9bb1820f5bf0baabb535c0463b71c6b2cf52788d956661b46938ed
7
- data.tar.gz: 11697818c4cfa90fd2ee9fd539c34e3d8e813129e277effd4376a6c3179a9ead45a939eedb73fd6d44068ba05c724be333221d1ac073e53c16642f4b53fea238
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
- ## Monday the 11th of November, v1.0.2 ##
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
@@ -2,7 +2,6 @@ source "https://rubygems.org"
2
2
 
3
3
  gemspec
4
4
 
5
- gem "wirble"
6
5
  group :test do
7
6
  gem "rspec"
8
7
  end
data/Rakefile CHANGED
@@ -5,8 +5,6 @@ Rake::TestTask.new(:test) do |test|
5
5
  test.verbose = true
6
6
  end
7
7
 
8
- task :test => :check_dependencies
9
-
10
8
  task :default => :test
11
9
 
12
10
 
@@ -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 + amount)
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 + diff)
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 + (7*amount))
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+amount, self.day)
59
+ Date.civil(self.year, self.month, self.day).next_month(amount)
62
60
  when :year then
63
- Date.civil(self.year + amount, self.month, self.day)
61
+ Date.civil(self.year, self.month, self.day).next_year(amount)
64
62
  else
65
- raise Exception, "type \"#{attr}\" not supported."
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 + amount, self.sec)
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 + amount, self.min, self.sec)
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 + amount, self.hour, self.min, self.sec)
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
- Time.local(self.year, self.month, self.day + diff, self.hour, self.min, self.sec)
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
- Time.local(self.year, self.month, self.day + (amount * 7), self.hour, self.min, self.sec)
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
- Time.local(self.year, self.month + amount, self.day, self.hour, self.min, self.sec)
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
- Time.local(self.year + amount, self.month, self.day, self.hour, self.min, self.sec)
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
 
@@ -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
@@ -1,5 +1,5 @@
1
1
  module Tickle
2
2
 
3
3
  # This library's current version.
4
- VERSION = "1.0.2"
4
+ VERSION = "1.1.0"
5
5
  end
@@ -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
- time = Tickle.parse("may 27", :today => 'something odd')
168
+ Tickle.parse("may 27", :today => 'something odd')
169
169
  end
170
170
 
171
171
  assert_raise(Tickle::InvalidArgumentException) do
172
- time = Tickle.parse("may 27", :foo => :bar)
172
+ Tickle.parse("may 27", :foo => :bar)
173
173
  end
174
174
 
175
175
  assert_raise(Tickle::InvalidArgumentException) do
176
- time = Tickle.parse(nil)
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
- time = Tickle.parse("every other day", {:start => past_date})
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, Date.today.day + 10)
186
- end_date = Date.civil(Date.today.year, Date.today.month, Date.today.day + 5)
187
- time = Tickle.parse("every other day", :start => start_date, :until => end_date)
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+2, Date.today.day)
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
@@ -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.2
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: 2015-01-26 00:00:00.000000000 Z
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
@@ -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