Class: EventCalendar::Event
- Inherits:
-
Object
- Object
- EventCalendar::Event
- Defined in:
- lib/event_calendar/event.rb
Overview
Provides conveniece methods for calculating dates and spans for an event. Stores the real event object for proxying all other method calls to it.
Instance Attribute Summary collapse
-
#event ⇒ Object
readonly
Returns the value of attribute event.
-
#options ⇒ Object
Returns the value of attribute options.
Instance Method Summary collapse
-
#days(week_start = start_date, week_end = end_date) ⇒ Object
Calculates the number of days this day takes up on a calendar (rounding up).
-
#end_date ⇒ Object
Returns the end date of the event.
-
#initialize(event, options) ⇒ Event
constructor
Accepts a real event object which it stores to proxy method calls to, and a hash of options obtained from the
EventCalendar
instance. -
#method_missing(method, *args) ⇒ Object
Allows you to read options starting with
:event_
using method notation. -
#start_date ⇒ Object
Returns the start date of the event.
Constructor Details
#initialize(event, options) ⇒ Event
Accepts a real event object which it stores to proxy method calls to, and a hash of options obtained from the EventCalendar
instance.
14 15 16 |
# File 'lib/event_calendar/event.rb', line 14 def initialize(event, ) @event, @options = event, end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args) ⇒ Object
Allows you to read options starting with :event_
using method notation.
For example: calling @event.title
will return the value of @event.options[:event_title]
if that option exists.
All other calls are delegated to the real :event
object.
42 43 44 45 46 47 48 49 |
# File 'lib/event_calendar/event.rb', line 42 def method_missing(method, *args) option = "event_#{method}".to_sym if @options.has_key?(option) evaluate_option(option) else @event.send(method, *args) end end |
Instance Attribute Details
#event ⇒ Object (readonly)
Returns the value of attribute event.
10 11 12 |
# File 'lib/event_calendar/event.rb', line 10 def event @event end |
#options ⇒ Object
Returns the value of attribute options.
9 10 11 |
# File 'lib/event_calendar/event.rb', line 9 def @options end |
Instance Method Details
#days(week_start = start_date, week_end = end_date) ⇒ Object
Calculates the number of days this day takes up on a calendar (rounding up). Optionally accepts week_start
and week_end
dates to calculate how many days an event takes up in a single week. For example, if an event started on a Friday and ended the following Wednesday, calling @event.days(the_sunday_after_the_event_starts)
would return 4.
22 23 24 |
# File 'lib/event_calendar/event.rb', line 22 def days(week_start = start_date, week_end = end_date) (end_date > week_end ? week_end : end_date) - (start_date < week_start ? week_start : start_date) + 1 end |
#end_date ⇒ Object
Returns the end date of the event. If the event stores its end as a datetime then it is converted to a date.
27 28 29 |
# File 'lib/event_calendar/event.rb', line 27 def end_date self.end.to_date end |
#start_date ⇒ Object
Returns the start date of the event. If the event stores its start as a datetime then it is converted to a date.
32 33 34 |
# File 'lib/event_calendar/event.rb', line 32 def start_date start.to_date end |