TickTack
TickTack is a lean wrapper for Rubys native Date
object to provide some
helpful methods for easy calendar creation. See the Example section below for
a better unterstanding!
Installation
Add this line to your application's Gemfile:
gem 'tick_tack'
And then execute:
$ bundle
Or install it yourself as:
$ gem install tick_tack
Usage
Calendar
Create a new calendar object
calendar = TickTack::Calendar.new
To overwrite the current date just pass in another date.
This date is used as a fallback for the factory methods.
For example - if you call calendar.month(2014)
without a month,
it will return the current month but in year 2014.
TickTack::Calendar.new(Date.new(2015, 5, 27))
Methods
-
calendar.now
Returns the calendars baseDate
-
calendar.year(2013)
Returns theYear
for the given year number -
calendar.month(2013, 1)
Returns theMonth
for the given year and month -
calendar.day(2013, 1, 12)
Returns theDay
for the given year, month and day
Year
To get a year from the calendar call the year
on the calendar object
year = calendar.year(2014)
Methods
-
year.first_day
Get the first day of the year -
year.last_day
Get the last day of the year -
year.month(2)
Get theMonth
february in this year -
year.months
Get all months as an array for this year -
year.contains?(other)
Check if other is part of this year.other
can be either aMonth
or aDay
-
year.next
Get the nextYear
-
year.previous
Get the previousYear
Month
To get a month, you can either call the creator method on the calendar or on the Year
:
month = calendar.month(2014, 5)
# or
month = year.month(5)
Methods
-
month.first_day
Get the first day of the month -
month.last_day
Get the last day of the month -
month.day(2)
Get the requestedDay
on this month -
month.weekdays
Gets an array of all weeks from this month containing all days. Including overlapping days in other months. This is useful for rendering a month-view of an calendar. -
month.contains?(day)
Check if aDay
is part of this month -
month.next
Get the nextMonth
-
month.previous
Get the previousMonth
Day
A day can be created from a calendar or month:
day = calendar.day(2014, 5, 30)
# or
day = month.day(30)
Methods
-
day.week_start
Returns the firstDay
of the week which the current day is in. To configure the first day of the week, see Localization section below. -
day.week_end
Returns the lastDay
of the week which the current day is in. -
day.weekdays
Returns an array ofDay
s for the week in which the current day is in. -
day.next
Returns the nextDay
-
day.previous
Returns the previousDay
Localization
Currently only dow (day of week) value can be overwritten which usually starts with 0. To set the day to monday, just pass in the locale config as second argument:
calendar = TickTack::Calendar.new(nil, {dow: 1})
Example
TODO... maybe tomorrow :)
Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/tomraithel/tick_tack.
License
The gem is available as open source under the terms of the MIT License.