Class: EventCal::Calendar
- Inherits:
-
Object
- Object
- EventCal::Calendar
- Defined in:
- lib/event_cal/calendar.rb
Instance Attribute Summary collapse
-
#base_date ⇒ Object
Returns the value of attribute base_date.
-
#end_on ⇒ Object
Returns the value of attribute end_on.
-
#events ⇒ Object
Returns the value of attribute events.
-
#except_events ⇒ Object
Returns the value of attribute except_events.
-
#only_events ⇒ Object
Returns the value of attribute only_events.
-
#owner ⇒ Object
Returns the value of attribute owner.
-
#priority_events ⇒ Object
Returns the value of attribute priority_events.
-
#start_on ⇒ Object
Returns the value of attribute start_on.
Instance Method Summary collapse
- #dates ⇒ Object
- #events_on(date) ⇒ Object
- #fetch_events ⇒ Object
-
#initialize(date = Date.today, options = {}) ⇒ Calendar
constructor
A new instance of Calendar.
- #to_param ⇒ Object
Constructor Details
#initialize(date = Date.today, options = {}) ⇒ Calendar
Returns a new instance of Calendar.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/event_cal/calendar.rb', line 6 def initialize(date = Date.today, = {} ) parse_initializer_arguments(date, ) # TODO: use beginning_of_week(:sunday) after migrates to rails 3.2 @start_on = @base_date.beginning_of_month.beginning_of_week.advance(:days => -1) @end_on = @base_date.end_of_month.end_of_week.advance(:days => -1) if @start_on <= @base_date.beginning_of_month - 7.day @start_on = @base_date.beginning_of_month end if @end_on < @base_date.end_of_month @end_on = @base_date.end_of_month.end_of_week.advance(:days => 6) end fetch_events end |
Instance Attribute Details
#base_date ⇒ Object
Returns the value of attribute base_date.
4 5 6 |
# File 'lib/event_cal/calendar.rb', line 4 def base_date @base_date end |
#end_on ⇒ Object
Returns the value of attribute end_on.
4 5 6 |
# File 'lib/event_cal/calendar.rb', line 4 def end_on @end_on end |
#events ⇒ Object
Returns the value of attribute events.
4 5 6 |
# File 'lib/event_cal/calendar.rb', line 4 def events @events end |
#except_events ⇒ Object
Returns the value of attribute except_events.
4 5 6 |
# File 'lib/event_cal/calendar.rb', line 4 def except_events @except_events end |
#only_events ⇒ Object
Returns the value of attribute only_events.
4 5 6 |
# File 'lib/event_cal/calendar.rb', line 4 def only_events @only_events end |
#owner ⇒ Object
Returns the value of attribute owner.
4 5 6 |
# File 'lib/event_cal/calendar.rb', line 4 def owner @owner end |
#priority_events ⇒ Object
Returns the value of attribute priority_events.
4 5 6 |
# File 'lib/event_cal/calendar.rb', line 4 def priority_events @priority_events end |
#start_on ⇒ Object
Returns the value of attribute start_on.
4 5 6 |
# File 'lib/event_cal/calendar.rb', line 4 def start_on @start_on end |
Instance Method Details
#dates ⇒ Object
23 24 25 |
# File 'lib/event_cal/calendar.rb', line 23 def dates (@start_on..@end_on).to_a end |
#events_on(date) ⇒ Object
46 47 48 |
# File 'lib/event_cal/calendar.rb', line 46 def events_on(date) @events.select{ |event| event.held_on == date } end |
#fetch_events ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/event_cal/calendar.rb', line 27 def fetch_events subclasses = if @only_events.present? if @priority_events.present? @priority_events & @only_events else @only_events end elsif @except_events.present? (@priority_events | ::EventCal::Event.subclasses) - @except_events else @priority_events | ::EventCal::Event.subclasses end @events = subclasses.map { |klass| klass.fetch_events(self) }.flatten end |
#to_param ⇒ Object
50 51 52 |
# File 'lib/event_cal/calendar.rb', line 50 def to_param "#{base_date.year}/#{base_date.month}/#{base_date.day}" end |