Module: CacheReduce::Magic

Defined in:
lib/cache_reduce.rb

Instance Method Summary collapse

Instance Method Details

#all(options = {}) ⇒ Object



6
7
8
# File 'lib/cache_reduce.rb', line 6

def all(options = {})
  reduce(fetch(options).values)
end

#by_day(options = {}) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/cache_reduce.rb', line 10

def by_day(options = {})
  result = fetch(options)
  time_range = result.keys.first..result.keys.last
  days = [time_range.first.beginning_of_day]
  while day = days.last + 1.day and time_range.cover?(day)
    days << day
  end
  grouped = result.group_by{|k, v| k.beginning_of_day }

  final = {}
  days.each do |day|
    final[day] = reduce((grouped[day] || []).map(&:last))
  end
  final
end

#by_hour(options = {}) ⇒ Object



26
27
28
# File 'lib/cache_reduce.rb', line 26

def by_hour(options = {})
  fetch(options)
end