Class: MonthlyBucketChangeCriteria

Inherits:
BucketChangeCriteria show all
Defined in:
lib/quartz_flow/usagetracker.rb

Instance Method Summary collapse

Methods inherited from BucketChangeCriteria

#innerNewBucket

Constructor Details

#initialize(resetDay) ⇒ MonthlyBucketChangeCriteria

Returns a new instance of MonthlyBucketChangeCriteria.



176
177
178
# File 'lib/quartz_flow/usagetracker.rb', line 176

def initialize(resetDay)
  @resetDay = resetDay
end

Instance Method Details

#criteriaDataObject



191
192
193
194
195
196
197
# File 'lib/quartz_flow/usagetracker.rb', line 191

def criteriaData
  now = Time.new
  nextMonth = now.mon % 12 + 1
  year = now.year
  year += 1 if nextMonth == 1
  Time.local(year, nextMonth, @resetDay)
end

#newBucketObject



184
185
186
187
188
189
# File 'lib/quartz_flow/usagetracker.rb', line 184

def newBucket
  now = Time.new
  # Set the bucket's criteriaData to the date after which we need a new bucket.
  data = criteriaData
  Bucket.new(now.strftime("%b %Y"), data, 0)
end

#newBucket?(currentBucket) ⇒ Boolean

Returns:

  • (Boolean)


180
181
182
# File 'lib/quartz_flow/usagetracker.rb', line 180

def newBucket?(currentBucket)
  Time.new > currentBucket.criteriaData
end