montrose 0.13.0 → 0.15.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -10,32 +10,32 @@ module Montrose
10
10
  @every = @options.fetch(:every) { fail ConfigurationError, "Required option :every not provided" }
11
11
  @interval = @options.fetch(:interval)
12
12
  @start_time = @options.fetch(:start_time)
13
- @at = @options.fetch(:at, nil)
13
+ @at = @options.fetch(:at, []).sort
14
14
  end
15
15
 
16
16
  # Advances time to new unit by increment and sets
17
17
  # new time as "current" time for next tick
18
18
  #
19
19
  def tick
20
- @time = peek
20
+ @time = next_time(true)
21
21
  end
22
22
 
23
23
  def peek
24
- return @start_time if @time.nil?
24
+ next_time(false)
25
+ end
25
26
 
26
- if @at
27
- times = @at.map { |hour, min, sec = 0| @time.change(hour: hour, min: min, sec: sec) }
27
+ private
28
28
 
29
- (min_next = times.select { |t| t > @time }.min) && (return min_next)
29
+ def next_time(tick)
30
+ return @start_time if @time.nil?
30
31
 
31
- advance_step(times.min || @time)
32
+ if @at.present?
33
+ next_time_at(@time, tick)
32
34
  else
33
35
  advance_step(@time)
34
36
  end
35
37
  end
36
38
 
37
- private
38
-
39
39
  def advance_step(time)
40
40
  time.advance(step)
41
41
  end
@@ -54,6 +54,51 @@ module Montrose
54
54
  unit_step(:year)
55
55
  end
56
56
 
57
+ # @private
58
+ #
59
+ # Returns next time using :at option. Tries to calculate
60
+ # a time for the current date by incrementing the index
61
+ # of the :at option. Once all items have been exhausted
62
+ # the minimum time is generated for the current date and
63
+ # we advance to the next date based on interval
64
+ #
65
+ def next_time_at(time, tick)
66
+ if current_at_index && (next_time = time_at(time, current_at_index + 1))
67
+ @current_at_index += 1 if tick
68
+
69
+ next_time
70
+ else
71
+ min_time = time_at(time, 0)
72
+ @current_at_index = 0 if tick
73
+
74
+ advance_step(min_time)
75
+ end
76
+ end
77
+
78
+ # @private
79
+ #
80
+ # Returns time with hour, minute and second from :at option
81
+ # at specified index
82
+ #
83
+ def time_at(time, index)
84
+ parts = @at[index]
85
+
86
+ return unless parts
87
+
88
+ hour, min, sec = parts
89
+ time.change(hour: hour, min: min, sec: sec || 0)
90
+ end
91
+
92
+ # @private
93
+ #
94
+ # Keep track of which index we are currently at for :at option.
95
+ #
96
+ def current_at_index
97
+ @current_at_index ||= @at.index do |hour, min, sec = 0|
98
+ @start_time.hour == hour && @start_time.min == min && @start_time.sec == sec
99
+ end
100
+ end
101
+
57
102
  # @private
58
103
  #
59
104
  # Returns hash representing unit and amount to advance time
@@ -104,7 +104,7 @@ module Montrose
104
104
  protected
105
105
 
106
106
  def interval_str
107
- @interval != 1 ? "*/#{@interval}" : "*"
107
+ (@interval != 1) ? "*/#{@interval}" : "*"
108
108
  end
109
109
  end
110
110
  end
data/lib/montrose/ical.rb CHANGED
@@ -71,9 +71,9 @@ module Montrose
71
71
  end
72
72
 
73
73
  def parse_timezone(time_string)
74
- time_zone_rule, _ = time_string.split(":")
75
- _label, time_zone = (time_zone_rule || "").split("=")
76
- time_zone
74
+ time_zone_rule, _ = time_string.split(":")
75
+ _label, time_zone = (time_zone_rule || "").split("=")
76
+ time_zone
77
77
  end
78
78
 
79
79
  def parse_time(time_string)
@@ -227,13 +227,13 @@ module Montrose
227
227
  return dump(load(obj)) if obj.is_a?(String)
228
228
 
229
229
  hash = case obj
230
- when Hash
231
- obj
232
- when self
233
- obj.to_hash
234
- else
235
- fail SerializationError,
236
- "Object was supposed to be a #{self}, but was a #{obj.class}. -- #{obj.inspect}"
230
+ when Hash
231
+ obj
232
+ when self
233
+ obj.to_hash
234
+ else
235
+ fail SerializationError,
236
+ "Object was supposed to be a #{self}, but was a #{obj.class}. -- #{obj.inspect}"
237
237
  end
238
238
 
239
239
  JSON.dump(hash)
@@ -35,13 +35,13 @@ module Montrose
35
35
  return dump(load(obj)) if obj.is_a?(String)
36
36
 
37
37
  array = case obj
38
- when Array
39
- new(obj).to_a
40
- when self
41
- obj.to_a
42
- else
43
- fail SerializationError,
44
- "Object was supposed to be a #{self}, but was a #{obj.class}. -- #{obj.inspect}"
38
+ when Array
39
+ new(obj).to_a
40
+ when self
41
+ obj.to_a
42
+ else
43
+ fail SerializationError,
44
+ "Object was supposed to be a #{self}, but was a #{obj.class}. -- #{obj.inspect}"
45
45
  end
46
46
 
47
47
  JSON.dump(array)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Montrose
4
- VERSION = "0.13.0"
4
+ VERSION = "0.15.0"
5
5
  end
data/montrose.gemspec CHANGED
@@ -20,14 +20,15 @@ Gem::Specification.new do |spec|
20
20
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
21
  spec.require_paths = ["lib"]
22
22
 
23
- spec.required_ruby_version = ">= 2.6.0"
23
+ spec.required_ruby_version = ">= 2.7.0"
24
24
 
25
25
  spec.add_dependency "activesupport", ">= 5.2", "< 7.1"
26
26
 
27
- spec.add_development_dependency "appraisal"
27
+ spec.add_development_dependency "coveralls"
28
28
  spec.add_development_dependency "m"
29
29
  spec.add_development_dependency "minitest"
30
30
  spec.add_development_dependency "rake", ">= 12.3.3"
31
31
  spec.add_development_dependency "standard"
32
32
  spec.add_development_dependency "timecop"
33
+ spec.add_development_dependency "yard"
33
34
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: montrose
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.13.0
4
+ version: 0.15.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ross Kaffenberger
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-01-14 00:00:00.000000000 Z
11
+ date: 2023-08-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -31,7 +31,7 @@ dependencies:
31
31
  - !ruby/object:Gem::Version
32
32
  version: '7.1'
33
33
  - !ruby/object:Gem::Dependency
34
- name: appraisal
34
+ name: coveralls
35
35
  requirement: !ruby/object:Gem::Requirement
36
36
  requirements:
37
37
  - - ">="
@@ -114,6 +114,20 @@ dependencies:
114
114
  - - ">="
115
115
  - !ruby/object:Gem::Version
116
116
  version: '0'
117
+ - !ruby/object:Gem::Dependency
118
+ name: yard
119
+ requirement: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ type: :development
125
+ prerelease: false
126
+ version_requirements: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - ">="
129
+ - !ruby/object:Gem::Version
130
+ version: '0'
117
131
  description: A library for specifying, quering, and enumerating recurring events for
118
132
  calendars in Ruby.
119
133
  email:
@@ -125,16 +139,18 @@ files:
125
139
  - ".circleci/config.yml"
126
140
  - ".codeclimate.yml"
127
141
  - ".gitignore"
128
- - Appraisals
142
+ - ".rubocop.yml"
143
+ - ".ruby-version"
129
144
  - CHANGELOG.md
130
145
  - CODE_OF_CONDUCT.md
131
146
  - Gemfile
147
+ - Gemfile.lock
132
148
  - Guardfile
133
149
  - LICENSE.txt
134
150
  - README.md
135
151
  - Rakefile
136
152
  - bin/_guard-core
137
- - bin/appraisal
153
+ - bin/bundle-all
138
154
  - bin/console
139
155
  - bin/guard
140
156
  - bin/m
@@ -142,9 +158,13 @@ files:
142
158
  - bin/setup
143
159
  - bin/standardrb
144
160
  - gemfiles/activesupport_5.2.gemfile
161
+ - gemfiles/activesupport_5.2.gemfile.lock
145
162
  - gemfiles/activesupport_6.0.gemfile
163
+ - gemfiles/activesupport_6.0.gemfile.lock
146
164
  - gemfiles/activesupport_6.1.gemfile
165
+ - gemfiles/activesupport_6.1.gemfile.lock
147
166
  - gemfiles/activesupport_7.0.gemfile
167
+ - gemfiles/activesupport_7.0.gemfile.lock
148
168
  - lib/montrose.rb
149
169
  - lib/montrose/chainable.rb
150
170
  - lib/montrose/clock.rb
@@ -205,14 +225,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
205
225
  requirements:
206
226
  - - ">="
207
227
  - !ruby/object:Gem::Version
208
- version: 2.6.0
228
+ version: 2.7.0
209
229
  required_rubygems_version: !ruby/object:Gem::Requirement
210
230
  requirements:
211
231
  - - ">="
212
232
  - !ruby/object:Gem::Version
213
233
  version: '0'
214
234
  requirements: []
215
- rubygems_version: 3.2.32
235
+ rubygems_version: 3.4.6
216
236
  signing_key:
217
237
  specification_version: 4
218
238
  summary: Recurring events in Ruby
data/Appraisals DELETED
@@ -1,17 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- appraise "activesupport-7.0" do
4
- gem "activesupport", "~> 7.0"
5
- end
6
-
7
- appraise "activesupport-6.1" do
8
- gem "activesupport", "~> 6.1"
9
- end
10
-
11
- appraise "activesupport-6.0" do
12
- gem "activesupport", "~> 6.0"
13
- end
14
-
15
- appraise "activesupport-5.2" do
16
- gem "activesupport", "~> 5.2"
17
- end
data/bin/appraisal DELETED
@@ -1,17 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # frozen_string_literal: true
3
- #
4
- # This file was generated by Bundler.
5
- #
6
- # The application 'appraisal' is installed as part of a gem, and
7
- # this file is here to facilitate running it.
8
- #
9
-
10
- require "pathname"
11
- ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
12
- Pathname.new(__FILE__).realpath)
13
-
14
- require "rubygems"
15
- require "bundler/setup"
16
-
17
- load Gem.bin_path("appraisal", "appraisal")