Class: DataCalendar

Inherits:
Object
  • Object
show all
Defined in:
lib/data_calendar/data_calendar.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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(options = {})
   @date = options[:date] 
   @date = @date.to_date
   @previous_month = options[:previous_month] || :previous_month
   @date_method = options[:date_method] || :start_at 
   @next_month = options[:next_month] || :next_month
   @events = options[:events] || [] 
   
end

Instance Attribute Details

#date_methodObject

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

#eventsObject

Returns the value of attribute events.



3
4
5
# File 'lib/data_calendar/data_calendar.rb', line 3

def events
  @events
end

#next_monthObject

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_monthObject

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_daysObject



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_monthObject



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_monthObject



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_monthObject



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_monthObject



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_monthObject



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

#weekObject

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