Scheduling Recurring Events with Ice Cube Gem

Ice_cube is a ruby library for effectively taking care of repeated events (schedules). The force lies in the ability to indicate multiple rules, and have ice_cube rapidly make sense of whether the schedule falls on a specific date (.occurs_on?), or what times it happens at (.occurrences, .first, .all_occurrences).
How to get ice cube
For install use the below syntax
gem install
if you want to get the code
gem clone git://github.com/seejohnrun/ice_cube
For creating icecube schedule
schedule = IceCube::Schedule.new
if we want to speciy startdate and enddate we have option to specify in the above mentioned schedule
schedule = IceCube::Schedule.new(start = Time.now, :end_time => start + 600)
Daily schedules
After creating schedule we have an option to add recurrence rule for the above mentioned schedule
consider “schedule every day” on above mentioned time
schedule.add_recurrence_rule IceCube::Rule.daily
consider the same schedule with repeat “n” number of days
schedule.add_recurrence_rule IceCube::Rule.daily(repeat_every_n_days)
in place of repeat_every_n_days you have option to specify the number of days
Weekly schedules
Recurring rule to generate weekly schedule
schedule.add_recurrence_rule IceCube::Rule.weekly
recurring rule to add repeat n number of weeks with the same schedule
schedule.add_recurrence_rule IceCube::Rule.weekly(repeat_every_n_weeks)
Consider an example repeat the schedule on only week days (monday to friday)
schedule.add_recurrence_rule IceCube::Rule.weekly.day(1, 2, 3, 4, 5)
Every other week on monday and tuesday
schedule.add_recurrence_rule IceCube::Rule.weekly(2).day(:monday, :tuesday)
or you can mention as
schedule.add_recurrence_rule IceCube::Rule.weekly(2).day(:monday, :tuesday)
Monthly schedules
repeat the same schedule on every month
schedule.add_recurrence_rule IceCube::Rule.montly
Monthly schedules(by day of Month)
every month on the first and last days of the month
schedule.add_recurrence_rule IceCube::Rule.monthly.day_of_month(1, -1)
every other month on the 15th of the month
schedule.add_recurrence_rule IceCube::Rule.monthly(2).day_of_month(15)
Monthly (by day of Nth week)
# every month on the first and last tuesdays of the month
schedule.add_recurrence_rule IceCube::Rule.monthly.day_of_week(:tuesday => [1, -1])
# every other month on the first monday and last tuesday
schedule.add_recurrence_rule IceCube::Rule.monthly(2).day_of_week(:monday => [1],:tuesday => [-1])
Yearly(by day of year)
# every year on the 100th days from the beginning and end of the year
schedule.add_recurrence_rule IceCube::Rule.yearly.day_of_year(100, -100)
# every fourth year on new year’s eve
schedule.add_recurrence_rule IceCube::Rule.yearly(4).day_of_year(-1)
Yearly (by month of year)
# every year on the same day as start_time but in january and february
schedule.add_recurrence_rule IceCube::Rule.yearly.month_of_year(:january, :februrary)
# every third year in march
schedule.add_recurrence_rule IceCube::Rule.yearly(3).month_of_year(:march)
# for programatic convenience (same as above)
schedule.add_recurrence_rule IceCube::Rule.yearly(3).month_of_year(3)
Hourly (by hour of day)
# every hour on the same minute and second as start date
schedule.add_recurrence_rule IceCube::Rule.hourly
# every other hour, on mondays
schedule.add_recurrence_rule IceCube::Rule.hourly(2).day(:monday)
Minutely (every N minutes)
# every 10 minutes
schedule.add_recurrence_rule IceCube::Rule.minutely(10)
# every hour and a half, on the last tuesday of the month
schedule.add_recurrence_rule IceCube::Rule.minutely(90).day_of_week(:tuesday => [-1])
Read full article on here : Scheduling Recurring Events with Ice Cube Gem