Skip to content

Instantly share code, notes, and snippets.

@Electron-libre
Created July 28, 2011 12:38
Show Gist options
  • Save Electron-libre/1111463 to your computer and use it in GitHub Desktop.
Save Electron-libre/1111463 to your computer and use it in GitHub Desktop.
pending ...
module CallLog::Replay
# Class methods for CallLog
module ClassMethods
def replay_for(object, timestamp=Time.now.utc, kind='all')
case object.class
when Account
self.replay_account_from(object, timestamp, kind)
end
end
def replay_account_from(account, timestamp, kind)
criterion = case kind
when 'billing'
CallLog.where(:in_account => account.code, :time.gte => timestamp)
when 'payback'
CallLog.where(:out_account => account.code, :time.gte => timestamp)
else
CallLog.any_of(:in_account => account.code, :out_account => account.code).and(:time.gte => timestamp)
end
criterion.each do |call_log|
call_log.replay(kind)
end
end
end
# Instance Methods for CallLog
module InstanceMethods
def replay(kind)
if kind == "all"
self.replay('billing')
self.replay('payback')
else
cdr = Cdr.new(:called_number => self.called, :deployment_id => self.vno_ref)
new_entry = {}
kind_account = (entry_kind == 'billing') && 'in_account' || 'out_account'
grid_id = Account.where(:code => call_log) account.send("get_current_#{entry_kind}_grid").try(:id)
destination = Destination.resolve(cdr, grid_id)
price_block = destination.get_price_block_for_account(call_log.send())
end
end
end
# When included we extend the including class
def self.included(base)
base.extend(ClassMethods)
base.class_eval do
include InstanceMethods
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment