Sha256: 21d822e86a3b8d21918592a353fbd476bcc5c6643c3cd825b30f2ce670c9b02a
Contents?: true
Size: 1.15 KB
Versions: 1
Compression:
Stored size: 1.15 KB
Contents
require 'event_calendar/event' class EventCalendar::Calendar attr_accessor :base_date, :start_on, :end_on, :events, :owner def initialize(date = Date.today, options = {} ) parse_initializer_arguments(date, options) # 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) fetch_events end def dates (@start_on..@end_on).to_a end def fetch_events @events = ::EventCalendar::Event.subclasses.map { |klass| klass.fetch_events(self) }.flatten end def events_on(date) @events.select{ |event| event.held_on == date } end private def parse_initializer_arguments(date, options) if date.class == Date @base_date = date opts = options elsif date.class == Hash @base_date = Date.today opts = date else raise ArgumentError.new('wrong argument for initializer') end opts.each do |key, value| if key == :owner @owner = value else #ignore other keys end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
event_cal-1.0 | lib/event_calendar/calendar.rb |