README.md in repeatable-0.1.0 vs README.md in repeatable-0.2.0

- old
+ new

@@ -22,23 +22,89 @@ $ gem install repeatable ## Usage -Describe a schedule with a Hash: +### Building a Schedule +You can create a schedule in one of two ways. + +#### Composed objects + +You can compose each of the expression objects manually. + ```ruby +second_monday = Repeatabe::Expression::WeekdayInMonth.new(weekday: 1, count: 2) +oct_thru_dec = Repeatable::Expression::RangeInYear.new(start_month: 10, end_month: 12) +intersection = Repeatable::Expresson::Intersection.new(second_monday, oct_thru_dec) + +schedule = Repeatable::Schedule.new(intersection) +``` + + +#### Hash + +Or you can describe the same structure with a `Hash`, and the gem will compose the objects for you. + +```ruby args = { intersection: [ # All included conditions must be met weekday_in_month: { weekday: 1, count: 2 } # The second Monday of every month range_in_year: { start_month: 10, end_month: 12 } # October through December ] } schedule = Repeatable::Schedule.new(args) ``` +- - - + +#### Time Expressions + +There are a number of time expressions available which, when combined, can describe most any schedule. + +```ruby +# SETS + +# Any conditions can be met +{ union: [] } +Repeatable::Expression::Union.new(expressions) + +# All conditions must be met +{ intersection: [] } +Repeatable::Expression::Intersection.new(expressions) + + +# DATES + +# Every Sunday +{ weekday: { weekday: 0 } } +Repeatable::Expression::Weekday.new(weekday: 0) + +# The 3rd Monday of every month +{ weekday_in_month: { weekday: 1, count: 3 } } +Repeatable::Expression::WeekdayInMonth.new(weekday: 1, count: 3) + +# The 13th of every month +{ day_in_month: { day: 13 } } +Repeatable::Expression::DayInMonth.new(day: 13) + +# Any day in October +{ range_in_year: { start_month: 10 } } +Repeatable::Expression::RangeInYear.new(start_month: 10) + +# All days from October through December +{ range_in_year: { start_month: 10, end_month: 12 } } +Repeatable::Expression::RangeInYear.new(start_month: 10, end_month: 12) + +# All days from October 1 through December 20 +{ range_in_year: { start_month: 10, end_month: 12, start_day: 1, end_day: 20 } } +Repeatable::Expression::RangeInYear.new(start_month: 10, end_month: 12, start_day: 1, end_day: 20) +``` + +### Getting information from a Schedule + Ask your schedule one of three questions: ```ruby schedule.next_occurrence # => Date of next occurrence @@ -46,31 +112,13 @@ schedule.occurrences(Date.new(2015, 1, 1), Date.new(2016, 6, 30)) # => Dates of all occurrences between Jan 1, 2015 and June 30, 2016 schedule.include?(Date.new(2015, 10, 10)) # => Whether the schedule has an event on the date given (true/false) -``` -Available time expressions: - -```ruby -# Sets -union: [] # Any conditions can be met -intersection: [] # All conditions must be met - -# Dates -weekday: { weekday: 0 } - # Every Sunday -weekday_in_month: { weekday: 1, count: 3 } - # The 3rd Monday of every month -day_in_month: { day: 13 } - # The 13th of every month -range_in_year: { start_month: 10 } - # Any day in October -range_in_year: { start_month: 10, end_month: 12 } - # All days from October through December -range_in_year: { start_month: 10, end_month: 12, start_day: 1, end_day: 20 } - # All days from October 1 through December 20 +schedule.to_h + # => Hash representation of the Schedule, which is useful for storage and + # can be used to recreating an identical Schedule object at a later time ``` ## Development After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.