Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Natural language parser for recurring events

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
lib
test
.document
.gitignore
.rvmrc
LICENSE
README.rdoc
Rakefile
SCENARIOS.rdoc
VERSION
tickle.gemspec

README.rdoc

tickle

http://github.com/noctivityinc/tickle
by Joshua Lippiner, Noctivity

– DESCRIPTION

Tickle is a natural language parser for recurring events.

Tickle is designed to be a compliment of Chronic and can interpret things such as “every 2 days, every Sunday, Sundays, Weekly, etc.”

Tickle has one main method, “Tickle.parse,” which returns two variables, the next interval followed by the interval length in days. Tickle returns nil if it cannot parse the string cannot be parsed.

– INSTALLATION

Tickle can be installed via RubyGems:

$ gem install tickle

– TINKERING

Everything's at Github - github.com/noctivityinc/tickle

– DEPENDENCIES

chronic gem (gem install chronic) thoughtbot's shoulda (gem install shoulda)

USAGE

You can parse strings containing a natural language interval using the Tickle.parse method.

Tickle.parse returns an array of first occurrence, next occurrence, interval between occurrences.

You can also pass a start date with the word “starting” (e.g. Tickle.parse('every 3 days starting next friday'))

Tickle HEAVILY uses chronic for parsing both the event and the start date.

– EXAMPLES

require 'rubygems'
require 'tickle'

Time.now
2010-04-22 16:38:12 -0400

Tickle.parse('each day')
#=> [2010-04-22 16:38:12 -0400, 2010-04-23 16:38:12 -0400, 1]

Tickle.parse('every day')
#=> [2010-04-22 16:38:12 -0400, 2010-04-23 16:38:12 -0400, 1]

Tickle.parse('every week')
#=> [2010-04-22 16:38:12 -0400, 2010-04-23 16:38:12 -0400, 7]

Tickle.parse('every Month')
#=> [2010-04-22 16:38:12 -0400, 2010-04-23 16:38:12 -0400, 30]

Tickle.parse('every year')
#=> [2010-04-22 16:38:12 -0400, 2010-04-23 16:38:12 -0400, 365]

Tickle.parse('daily')
#=> [2010-04-22 16:38:12 -0400, 2010-04-23 16:38:12 -0400, 1]

Tickle.parse('weekly')
#=> [2010-04-22 16:38:12 -0400, 2010-04-23 16:38:12 -0400, 7]

Tickle.parse('monthly')
#=> [2010-04-22 16:38:12 -0400, 2010-04-23 16:38:12 -0400, 30]

Tickle.parse('yearly')
#=> [2010-04-22 16:38:12 -0400, 2010-04-23 16:38:12 -0400, 365]

Tickle.parse('every 3 days')
#=> [2010-04-22 16:38:12 -0400, 2010-04-23 16:38:12 -0400, 3]

Tickle.parse('every 3 weeks')
#=> [2010-04-22 16:38:12 -0400, 2010-04-23 16:38:12 -0400, 21]

Tickle.parse('every 3 months')
#=> [2010-04-22 16:38:12 -0400, 2010-04-23 16:38:12 -0400, 90]

Tickle.parse('every 3 years')
#=> [2010-04-22 16:38:12 -0400, 2010-04-23 16:38:12 -0400, 1095]

Tickle.parse('every other day')
#=> [2010-04-22 16:38:12 -0400, 2010-04-23 16:38:12 -0400, 2]

Tickle.parse('every other week')
#=> [2010-04-22 16:38:12 -0400, 2010-04-23 16:38:12 -0400, 14]

Tickle.parse('every other month')
#=> [2010-04-22 16:38:12 -0400, 2010-06-22 16:38:12 -0400, 60]

Tickle.parse('every other year')
#=> [2010-04-22 16:38:12 -0400, 2012-04-22 16:38:12 -0400, 730]

Tickle.parse('every other day starting May 1st')
#=> [2010-05-01 12:00:00 -0400, 2012-04-22 16:38:12 -0400, 2]

Tickle.parse('every other week starting this Sunday')
#=> [2010-04-25 12:00:00 -0400, 2012-04-22 16:38:12 -0400, 14]

Tickle.parse('every Monday')
#=> [2010-04-26 12:00:00 -0400, 2012-04-22 16:38:12 -0400, 7]

Tickle.parse('every Wednesday')
#=> [2010-04-28 12:00:00 -0400, 2012-04-22 16:38:12 -0400, 7]

Tickle.parse('every Friday')
#=> [2010-04-23 12:00:00 -0400, 2012-04-22 16:38:12 -0400, 7]

Tickle.parse('every May')
#=> [2010-05-01 12:00:00 -0400, 2012-04-22 16:38:12 -0400, 30]

Tickle.parse('every june')
#=> [2010-06-01 12:00:00 -0400, 2012-04-22 16:38:12 -0400, 30]

Tickle.parse('beginning of the week')
#=> [2010-04-25 12:00:00 -0400, 2012-04-22 16:38:12 -0400, 7]

Tickle.parse('middle of the week')
#=> [2010-04-28 12:00:00 -0400, 2012-04-22 16:38:12 -0400, 7]

Tickle.parse('end of the week')
#=> [2010-04-24 12:00:00 -0400, 2012-04-22 16:38:12 -0400, 7]

Tickle.parse('beginning of the month')
#=> [2010-05-01 12:00:00 -0400, 2012-04-22 16:38:12 -0400, 30]

Tickle.parse('middle of the month')
#=> [2010-05-15 12:00:00 -0400, 2012-04-22 16:38:12 -0400, 30]

Tickle.parse('end of the month')
#=> [2010-04-30 00:00:00 -0400, 2012-04-22 16:38:12 -0400, 30]

Tickle.parse('beginning of the year')
#=> [2011-01-01 12:00:00 -0500, 2012-04-22 16:38:12 -0400, 365]

Tickle.parse('middle of the year')
#=> [2010-06-15 00:00:00 -0400, 2012-04-22 16:38:12 -0400, 365]

Tickle.parse('end of the year')
#=> [2010-12-31 00:00:00 -0500, 2012-04-22 16:38:12 -0400, 365]

You can either pass a string prefixed with the word “every, each or 'on the'” or simply the time frame.

– LIMITATIONS

Currently, Tickle only works for day intervals but feel free to fork and add time-based interval support or send me a note if you really want me to add it.

CREDIT

HUGE shout-out to both the creator of Chronic, Tom Preston-Werner (chronic.rubyforge.org/) as well as Brian Brownling who maintains a github version at github.com/mojombo/chronic.

Without their work and code structure I'd be lost.

Note on Patches/Pull Requests

  • Fork the project.

  • Make your feature addition or bug fix.

  • Add tests for it. This is important so I don't break it in a future version unintentionally.

  • Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)

  • Send me a pull request. Bonus points for topic branches.

Copyright

Copyright © 2010 Joshua Lippiner. See LICENSE for details.

Something went wrong with that request. Please try again.