Class: DataCalendar
- Inherits:
-
Object
- Object
- DataCalendar
- Defined in:
- lib/data_calendar/data_calendar.rb
Instance Method Summary collapse
- #all_days ⇒ Object
- #days_to_current_month ⇒ Object
- #days_to_next_month ⇒ Object
- #days_to_preview_month ⇒ Object
- #first_day_of_month ⇒ Object
-
#initialize(options = {}) ⇒ DataCalendar
constructor
A new instance of DataCalendar.
- #last_day_of_month ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ DataCalendar
Returns a new instance of DataCalendar.
2 3 4 5 6 7 |
# File 'lib/data_calendar/data_calendar.rb', line 2 def initialize( = {}) @date = [:date] || Time.now @date = @date.to_date @preview_month = [:preview_month] || :preview_month @next_month = [:next_month] || :next_month end |
Instance Method Details
#all_days ⇒ Object
9 10 11 |
# File 'lib/data_calendar/data_calendar.rb', line 9 def all_days [days_to_preview_month,days_to_current_month,days_to_next_month].flatten end |
#days_to_current_month ⇒ Object
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/data_calendar/data_calendar.rb', line 26 def days_to_current_month days = [] last_day_of_month.day.times do |time| type = [] day = first_day_of_month + time.day days << day_and_types(day) end days end |
#days_to_next_month ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/data_calendar/data_calendar.rb', line 37 def days_to_next_month fill_days = last_day_of_month.wday fill_days = 7 if fill_days == 0 fill_days = 7 - fill_days days = [] fill_days.times do |time| days << day_and_types( last_day_of_month + (time + 1).day, [@next_month]) end days end |
#days_to_preview_month ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/data_calendar/data_calendar.rb', line 13 def days_to_preview_month fill_days = first_day_of_month.wday fill_days = 7 if fill_days == 0 fill_days -= 1 first_day_of_month - fill_days.days days = [] fill_days.times do |time| days << day_and_types(first_day_of_month - (6 - time).day, [@preview_month]) end days end |
#first_day_of_month ⇒ Object
49 50 51 |
# File 'lib/data_calendar/data_calendar.rb', line 49 def first_day_of_month @date - (@date.mday - 1).day end |
#last_day_of_month ⇒ Object
53 54 55 |
# File 'lib/data_calendar/data_calendar.rb', line 53 def last_day_of_month first_day_of_month.next_month - 1.day end |