IceT
IceT is a ruby library for handling repeated events.
Installation
Add this line to your application's Gemfile:
gem 'ice_t'
And then execute:
$ bundle
Or install it yourself as:
$ gem install ice_t
Usage
Creating rules
rule = IceT::Rule::Secondly.new(42) # => step by 42 seconds
rule = IceT::Rule::Minutely.new(42) # => step by 42 minutes
rule = IceT::Rule::Hourly.new(42) # => step by 42 hours
rule = IceT::Rule::Daily.new(42) # => step by 42 days
rule = IceT::Rule::Weekly.new(42) # => step by 42 weeks
rule = IceT::Rule::Monthly.new(42) # => step by 42 months
rule = IceT::Rule::Yearly.new(42) # => step by 42 years
Get time occurrences
rule.occurrences # => Array of times
Schedule
The Schedule helps on dealing with multiple rules.
schedule = IceT::Schedule.new(start_time: Time.now, end_time: Time.now + 4.months)
schedule.add_rule my_daily_rule
schedule.add_rule my_monthly_rule
schedule.rules # => Array of rules
schedule.occurrences # => Merged occurrences
Persistence
Lets say you want to your Schedule in your database and use it later again. You can do this:
json = schedule.to_json
schedule = IceT::Schedule.from_json(json)
Tipps - doc in development
Sorting rules:
[r2,r1,r3].sort.collect(&:interval)
Comparing rules:
IceT::Rule::Daily.new(1) < IceT::Rule::Monthly.new(1) # => true
r2.between?(r1, r3)



