Module: TaQSimpleCalendar::Record

Included in:
ActiveRecord::Relation, Array
Defined in:
lib/taq_simple_calendar/record.rb

Instance Method Summary collapse

Instance Method Details

#calendarizeObject



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/taq_simple_calendar/record.rb', line 3

def calendarize
   collection  = self.sort_by {|c| c.start_at}
   months      = collection.inject({}) do |memo,col|
      %w(start_at end_at).each do |date|
         key, name = col.send(date).strftime("%Y-%m %B").split
         if !memo.key?(key)
            memo[key] = {}
            memo[key][:name] = name
            memo[key][:collection] = collection.select do |c| 
               c.start_at.strftime("%Y-%m") == key ||
               c.end_at.strftime("%Y-%m")   == key 
            end.map do |c|
               {:day          => c.send(:start_at).strftime("%02d"),
                :title        => c.send(:title),
                :bin_period   => c.send(:bin_period)
               }
            end
         end
      end
      memo
   end
end