Last active
August 29, 2015 14:02
-
-
Save beck03076/a68035d7cdf6b0b3a9cd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class CoreStatistics | |
| attr_accessor :all | |
| def initialize(users,core) | |
| @core = core | |
| @users = users | |
| @all = Hash.new { |h, k| h[k] = Hash.new } | |
| send(@core) | |
| end | |
| def all_statistics | |
| methods = (CoreStatistics.instance_methods(false) - [:all,:all=,:all_statistics,:enquiries,:registrations]).map &:to_s | |
| @users.each do |user| | |
| methods.each do |method| | |
| @all[method][user.id] = send(method,user) | |
| end | |
| end | |
| end | |
| def assigned(u) | |
| u.send(@core).size | |
| end | |
| def created(u) | |
| u.send(@core).where(created_by: u.id).size | |
| end | |
| def enquiries | |
| status_hash = {} | |
| EnquiryStatus.all.map {|i| status_hash[i.name] = i.id } | |
| status_hash.keys.each do |status| | |
| self.class.send(:define_singleton_method,"#{status}_enquiries") do |argument| | |
| argument.enquiries.where(status_id: status_hash[status]).size | |
| end | |
| end | |
| end | |
| def registrations | |
| status_hash = {} | |
| ApplicationStatus.all.map {|i| status_hash[i.name] = i.id } | |
| status_hash.keys.each do |status| | |
| define_method("#{status}") do |argument| | |
| argument.registrations.includes(:programmes).where(programmes: {app_status_id: status_hash[status]}).size | |
| end | |
| end | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment