Skip to content

Instantly share code, notes, and snippets.

@Jeiwan
Last active August 29, 2015 14:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Jeiwan/947de8cfe333759b42cc to your computer and use it in GitHub Desktop.
Save Jeiwan/947de8cfe333759b42cc to your computer and use it in GitHub Desktop.
require 'date'
module Stats
class << self
def calculate_stats(model, date_from = Date.today - 7, date_to = Date.today)
process_tracks(date_from, date_to).map do |track|
# Bar.get_stats_hash(track)
track
end
end
private
def process_tracks(date_from, date_to)
# tracks = Track.all
# (...)
%w(some useful and important stats)
end
end
end
# Stats.calculate_stats(Campaign, params[:date_from], params[:date_to])
class StatsClass
def initialize(model, date_from = Date.today - 7, date_to = Date.today)
@model = model
@date_from = date_from
@date_to = date_to
end
def calculate_stats
@stats ||= process_tracks.map do |track|
# Bar.get_stats_hash(track)
track
end
end
private
def process_tracks
# tracks = Track.all
# (...)
%w(some useful and important stats)
end
end
# StatsClass.new(Campaign, parmas[:date_from], params[:date_to]).calculate_stats
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment