Useful utilities to format dates and strings.
Add this line to your application's Gemfile:
gem 'cantab_utils'
And then execute:
$ bundle
Or install it yourself as:
$ gem install cantab_utils
require 'cantab_utils'
Then call the class methods on the appropriate formatter, DateFormatter
or StringFormatter
.
Outputs the date with four digit year, month spelt out in full and the day digit without leading zeros.
Cantab::DateFormatter.to_long(Date.new(2017,3,9))
=> "9 March 2017"
As with DateFormatter.to_long
, but separated by dashes.
Cantab::DateFormatter.to_long_dash(Date.new(2017,3,9))
=> "9-March-2017"
Outputs the date with four digit year, month and day digits separated by slashes, without leading zeros.
Cantab::DateFormatter.to_slash(Date.new(2017,3,9))
=> "9/3/2017"
Takes a date and an Integer, outputs the date that is the number of months after that date.
Cantab::DateFormatter.date_months_after(Date.new(2017,3,9), 5)
=> #<Date: 2017-08-09 ((2457975j,0s,0n),+0s,2299161j)>
Cantab::DateFormatter.date_months_after(Date.new(2017,3,9), 5).to_s
=> "2017-08-09"
Acts like ActiveSupport::Inflector's parameterize
method. Replaces special characters in a string so that it may be used as part of a 'pretty' URL.
Cantab::StringFormatter.parameterize("The rain in Spain stays mainly in the plain")
=> "The-rain-in-Spain-stays-mainly-in-the-plain"
Feel free to drop us a line to let us know you would like to work on something or if you have an idea. Otherwise, fork, code, commit, push and create pull request, viz:
- Create a fork of the repo.
- Create your feature branch (
git checkout -b new-feature
). - Write some tests (in RSpec, if you please).
- Write the code that allows the tests to pass.
- Commit your changes (
git commit -am 'Add some feature'
). - Push to the branch (
git push origin new-feature
). - Create a new [Pull Request] (https://help.github.com/articles/using-pull-requests).
More details on how to contribute can be found at this great Thoughtbot blogpost [8 (new) steps for fixing other people's code] (http://robots.thoughtbot.com/8-new-steps-for-fixing-other-peoples-code).
Copyright (c) 2017 Chong-Yee Khoo