Class: DataCalendar
- Inherits:
-
Object
- Object
- DataCalendar
- Defined in:
- lib/data_calendar/data_calendar.rb
Instance Attribute Summary collapse
-
#date_method ⇒ Object
Returns the value of attribute date_method.
-
#events ⇒ Object
Returns the value of attribute events.
-
#next_month ⇒ Object
Returns the value of attribute next_month.
-
#previous_month ⇒ Object
Returns the value of attribute previous_month.
Instance Method Summary collapse
- #all_days ⇒ Object
- #days_to_current_month ⇒ Object
- #days_to_next_month ⇒ Object
- #days_to_previous_month ⇒ Object
- #first_day_of_month ⇒ Object
-
#initialize(options = {}) ⇒ DataCalendar
constructor
A new instance of DataCalendar.
- #last_day_of_month ⇒ Object
-
#week ⇒ Object
Return the days of the current week.
Constructor Details
#initialize(options = {}) ⇒ DataCalendar
Returns a new instance of DataCalendar.
5 6 7 8 9 10 11 12 13 |
# File 'lib/data_calendar/data_calendar.rb', line 5 def initialize( = {}) @date = [:date] @date = @date.to_date @previous_month = [:previous_month] || :previous_month @date_method = [:date_method] || :start_at @next_month = [:next_month] || :next_month @events = [:events] || [] end |
Instance Attribute Details
#date_method ⇒ Object
Returns the value of attribute date_method.
3 4 5 |
# File 'lib/data_calendar/data_calendar.rb', line 3 def date_method @date_method end |
#events ⇒ Object
Returns the value of attribute events.
3 4 5 |
# File 'lib/data_calendar/data_calendar.rb', line 3 def events @events end |
#next_month ⇒ Object
Returns the value of attribute next_month.
3 4 5 |
# File 'lib/data_calendar/data_calendar.rb', line 3 def next_month @next_month end |
#previous_month ⇒ Object
Returns the value of attribute previous_month.
3 4 5 |
# File 'lib/data_calendar/data_calendar.rb', line 3 def previous_month @previous_month end |
Instance Method Details
#all_days ⇒ Object
16 17 18 |
# File 'lib/data_calendar/data_calendar.rb', line 16 def all_days [days_to_previous_month,days_to_current_month,days_to_next_month].flatten end |
#days_to_current_month ⇒ Object
46 47 48 49 50 51 52 53 54 55 |
# File 'lib/data_calendar/data_calendar.rb', line 46 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
57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/data_calendar/data_calendar.rb', line 57 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_previous_month ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/data_calendar/data_calendar.rb', line 32 def days_to_previous_month fill_days = first_day_of_month.wday fill_days = 7 if fill_days == 0 fill_days -= 1 days = [] fill_array = [] fill_days.times{|e| fill_array << e + 1} fill_array.reverse.each do |time| days << day_and_types(first_day_of_month - time.day, [@previous_month]) end days end |
#first_day_of_month ⇒ Object
69 70 71 |
# File 'lib/data_calendar/data_calendar.rb', line 69 def first_day_of_month @date - (@date.mday - 1).day end |
#last_day_of_month ⇒ Object
73 74 75 |
# File 'lib/data_calendar/data_calendar.rb', line 73 def last_day_of_month first_day_of_month.next_month - 1.day end |
#week ⇒ Object
Return the days of the current week
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/data_calendar/data_calendar.rb', line 21 def week first_day_of_week = @date.monday days_of_week = [] 7.times do |time| days_of_week << day_and_types(first_day_of_week + time.days) end days_of_week end |