Permalink
Browse files

Add documentation

  • Loading branch information...
1 parent ba8d12e commit 20ef5160b723ee7937e4a794de625aee044316a2 @seejohnrun committed Dec 7, 2011
Showing with 317 additions and 0 deletions.
  1. +1 −0 .rspec
  2. +47 −0 CHANGELOG
  3. +224 −0 README.rdoc
  4. +25 −0 Rakefile
  5. +20 −0 ice_cube.gemspec
View
@@ -0,0 +1 @@
+-fd -c
View
@@ -0,0 +1,47 @@
+0.6.0
+ * [#8] Changed how time serialization is done to preserve TimeWithZone when appropriate.
+ Backward compatibility is intact, but bumping the minor version for the YAML format change.
+ * [#11] Fixed next occurrence to work on never-ending schedules
+
+0.6.1
+ * Lessen the amount of info we store in yaml on the time zone
+
+0.6.2
+ * Patch release for to_yaml performance issue
+
+0.6.3
+ * Change how active_support_occurs_on works
+ * Fixed bug where next_occurrence wouldn't work if no end_date was set
+
+0.6.4
+ * Fixed bug where next_occurrence wouldn't actually grab the correct next occurrence with
+ schedules that had more than one recurrence rule and/or a recurrence rule and a recurrence date
+ * Added next_occurrences function to schedule, allowing you to get the next N occurrences after a
+ given date
+
+0.6.5
+ * Added a :start_date_override option to from_hash / from_yaml (@sakrafd)
+
+0.6.9
+ * Added support for Schedule#occurs_between?
+
+0.6.10
+ * UNTIL date now serialized with time information
+
+0.6.11
+ * Added the ability to add and remove rdates, rrules, exdates, and exrules from a schedule
+
+0.6.12
+ * Be able to set the start_date and duration after creating a schedule
+
+0.6.13
+ * Fix by Ben Fyvie for daily rule crossing over a year boundary
+ * Additional accessor methods on validations and rules for easy use in microformats (thanks @jamesarosen)
+ * Fix for changing start date affecting schedules without reloading
+ * Fix for typo in active_support_occurs_between? causing load issues with ActiveSupport (thanks @carlthuringer)
+
+0.6.14
+ * Fixed a skipping issue around DST ending
+
+0.6.15
+ * Deserialize until_date properly in #to_hash and #to_yaml (thanks @promisedlandt)
View
@@ -0,0 +1,224 @@
+==ice_cube - easy date expansion
+
+ gem install ice_cube
+
+ice_cube is a ruby library for easily handling repeated events (schedules). The API is modeled after iCalendar repeated dates. The power lies in the ability to specify multiple rules and dates, and have ice_cube quickly figure out whether the schedule falls on a certain date (.occurs_on?), or what dates it occurs on (.occurrences, .first, .all_occurrences)
+
+Imagine you want:
+
+ Every friday the 13th that falls in October
+
+You would write:
+
+ schedule.add_recurrence_rule Rule.yearly.day_of_month(13).day(:friday).month_of_year(:october)
+
+---
+
+=== Quick Introductions
+
+* Presentation from Lone Star Ruby Conf - http://seejohncode.com/ice_cube/static/ice_cube_ruby_nyc.pdf
+* Quick Introduction - http://seejohncode.com/ice_cube/
+
+---
+
+With ice_cube, you can specify (in order of precendence)
+
+* Exception Dates - To specifically exclude from a schedule
+* Recurrence Dates - To specifically include in a schedule
+* Exception Rules - Rules on how to exclude recurring dates in a schedule
+* Recurrence Rules - Rules on how to include recurring dates in a schedule
+
+EX: Specifying a exception/recurrence date:
+
+ schedule = Schedule.new(start_date)
+ schedule.add_recurrence_date(Time.now)
+ schedule.add_exception_date(Time.now + 1)
+
+ # list all occurrences from start_date to end_date
+ occurrences = schedule.occurrences(end_date) # [Time.now]
+
+ # or all of the occurrences
+ occurrences = schedule.all_occurrences # [Time.now]
+
+ # or check just a single time
+ schedule.occurs_at?(Time.now) # true
+
+ # or check just a single day
+ schedule.occurs_on?(Date.new) # true
+
+ # or check whether it occurs between two dates
+ schedule.occurs_between?(Time.now, Time.now + 30.days) # true
+ schedule.occurs_between?(Time.now + 3.days, Time.now + 30.days) # false
+
+ # or the first (n) occurrences
+ schedule.first(n) # [Time.now]
+ schedule.first # Time.now
+
+ # or the next occurrence
+ schedule.next_occurrence([from_date]) # defaults to Time.now
+ schedule.remaining_occurrences
+ schedule.next_occurrences(3, [from_date])
+
+ # or give the schedule a duration and ask if occurring_at?
+ schedule = Schedule.new(Time.now, :duration => 3600)
+ schedule.occurring_at?(Time.now + 1800) # true
+
+ # you can also give schedules a solidified end_time
+ schedule = Schedule.new(Time.now, :end_time => Time.now + 3600)
+ schedule.occurs_at?(Time.now + 3601) # false
+
+The reason that schedules have durations and not individual rules, is to maintain compatability with the ical RFC: http://www.kanzaki.com/docs/ical/rrule.html
+
+---
+
+===Persistence
+
+ice_cube implements its own hash-based .to_yaml, so you can quickly (and safely) serialize schedule objects in and out of your data store
+
+ yaml = schedule.to_yaml
+ Schedule.from_yaml(yaml)
+
+ hash = schedule.to_hash
+ Schedule.from_hash(hash)
+
+ Schedule.from_yaml(yaml, :start_date_override => Time.now)
+ Schedule.from_hash(hash, :start_date_override => Time.now)
+
+note: If you're using IceCube with Rails - you may want to check out https://github.com/ablegray/schedule-attributes
+
+---
+
+===Using your words
+
+ice_cube can provide ical or string representations of individual rules.
+
+ rule = Rule.daily(2).day_of_week(:tuesday => [1, -1], :wednesday => [2])
+
+ rule.to_ical # 'FREQ=DAILY;INTERVAL=2;BYDAY=1TU,-1TU,2WE'
+
+ rule.to_s # 'Every 2 days on the last and 1st Tuesdays and the 2nd Wednesday'
+
+---
+
+All rules are based off of the schedule's start date.
+Individual rules may optionally specify an until date, which is a date that that individual rule is no longer effective, or a count (which is how many times maximum you want the rule to be effective)
+
+---
+
+There are many types of recurrence rules that can be added to a schedule:
+
+===Daily
+
+ # every day
+ schedule.add_recurrence_rule Rule.daily
+
+ # every third day
+ schedule.add_recurrence_rule Rule.daily(3)
+
+===Weekly
+
+ # every week
+ schedule.add_recurrence_rule Rule.weekly
+
+ # every other week on monday and tuesday
+ schedule.add_recurrence_rule Rule.weekly(2).day(:monday, :tuesday)
+
+ # for programatic convenience (same as above)
+ schedule.add_recurrence_rule Rule.weekly(2).day(1, 2)
+
+===Monthly (by day of month)
+
+ # every month on the first and last days of the month
+ schedule.add_recurrence_rule Rule.monthly.day_of_month(1, -1)
+
+ # every other month on the 15th of the month
+ schedule.add_recurrence_rule Rule.monthly(2).day_of_month(15)
+
+===Monthly (by day of week)
+
+ # every month on the first and last tuesdays of the month
+ schedule.add_recurrence_rule Rule.monthly.day_of_week(:tuesday => [1, -1])
+
+ # every other month on the first monday and last tuesday
+ schedule.add_recurrence_rule Rule.monthly(2).day_of_week(:monday => [1], :tuesday => [-1])
+
+ # for programatic convenience (same as above)
+ schedule.add_recurrence_rule Rule.monthly(2).day_of_week(1 => [1], 2 => [-1])
+
+===Yearly (by day of year)
+
+ # every year on the 100th day from the beginning and end of the year
+ schedule.add_recurrence_rule Rule.yearly.day_of_year(100, -100)
+
+ # every fourth year on new year's eve
+ schedule.add_recurrence_rule Rule.yearly(4).day_of_year(-1)
+
+===Yearly (by month of year)
+
+ # every year on the same day as start_date but in january and february
+ schedule.add_recurrence_rule Rule.yearly.month_of_year(:january, :februrary)
+
+ # every third year in march
+ schedule.add_recurrence_rule Rule.yearly(3).month_of_year(:march)
+
+ # for programatic convenience (same as above)
+ schedule.add_recurrence_rule 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 Rule.hourly
+
+ # every other hour, on mondays
+ schedule.add_recurrence_rule Rule.hourly(2).day(:monday)
+
+===Minutely (by minute of hour)
+
+ # every 10 minutes
+ schedule.add_recurrence_rule Rule.minutely(10)
+
+ # every hour and a half, on the last tuesday of the month
+ schedule.add_recurrence_rule Rule.minutely(90).day_of_week(:tuesday => [-1])
+
+===Secondly (by second of minute)
+
+ # every second
+ schedule.add_recurrence_rule Rule.secondly
+
+ # every 15 seconds between 12 - 12:59
+ schedule.add_recurrence_rule Rule.secondly(15).hour_of_day(12)
+
+---
+
+===Contributors
+
+* Mat Brown - mat@patch.com
+* Philip Roberts
+* @sakrafd
+
+---
+
+===Issues?
+
+Use the GitHub issue tracker
+
+===Contributing
+
+* Contributions are welcome - I use Lighthouse for bug fixes (accompanying failing tests are awesome) and feature requests
+* Submit via fork and pull request (include tests)
+* Stick with my code style, and don't get mad if I make style changes to your code (consistency is a key to readability)
+* If you're working on something major, shoot me a message beforehand
+
+---
+
+===License
+
+(The MIT License)
+
+Copyright © 2010 John Crepezzi
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the ‘Software’), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED ‘AS IS’, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
View
@@ -0,0 +1,25 @@
+require 'rspec/core/rake_task'
+require File.dirname(__FILE__) + '/lib/ice_cube/version'
+
+task :build => :test do
+ system "gem build ice_cube.gemspec"
+end
+
+task :release => :build do
+ # tag and push
+ system "git tag v#{IceCube::VERSION}"
+ system "git push origin --tags"
+ # push the gem
+ system "gem push ice_cube-#{IceCube::VERSION}.gem"
+end
+
+RSpec::Core::RakeTask.new(:test) do |t|
+ t.pattern = 'spec/**/*_spec.rb'
+ fail_on_error = true # be explicit
+end
+
+RSpec::Core::RakeTask.new(:rcov) do |t|
+ t.pattern = 'spec/**/*_spec.rb'
+ t.rcov = true
+ fail_on_error = true # be explicit
+end
View
@@ -0,0 +1,20 @@
+require File.dirname(__FILE__) + '/lib/ice_cube/version'
+
+spec = Gem::Specification.new do |s|
+
+ s.name = 'ice_cube'
+ s.author = 'John Crepezzi'
+ s.add_development_dependency('rspec')
+ s.description = 'ice_cube is a recurring date library for Ruby. It allows for quick, programatic expansion of recurring date rules.'
+ s.email = 'john@crepezzi.com'
+ s.files = Dir['lib/**/*.rb']
+ s.has_rdoc = true
+ s.homepage = 'http://seejohnrun.github.com/ice_cube/'
+ s.platform = Gem::Platform::RUBY
+ s.require_paths = ['lib']
+ s.summary = 'Ruby Date Recurrence Library'
+ s.test_files = Dir.glob('spec/*.rb')
+ s.version = IceCube::VERSION
+ s.rubyforge_project = "ice-cube"
+
+end

0 comments on commit 20ef516

Please sign in to comment.