Skip to content

Instantly share code, notes, and snippets.

@i5okie

i5okie/delema.rb Secret

Last active August 29, 2015 14:27
Show Gist options
  • Save i5okie/92e813eb10ccb40bd3fa to your computer and use it in GitHub Desktop.
Save i5okie/92e813eb10ccb40bd3fa to your computer and use it in GitHub Desktop.
one liner
require 'CSV'
require 'time'
calls = []
myhash = {:user => "", :date => "", :call => "", :start_time => "", :end_time => ""}
CSV.foreach('cdr.txt', :headers => false) do |row|
next if row[9].nil? || row[10].nil?
date = Time.parse(row[9])
itime = date.strftime("%l:%M:%S %p")
otime = Time.parse(row[10]).strftime("%l:%M:%S %p")
calls << [if row[122].empty?; "UNKNOWN" else row[122] end, date.strftime("%A %e, %B %Y"), row[13], itime, otime]
end
# for irb
calls
[{:user => "UNKNOWN", :date => "Tuesday 12, May 2015", :call => "originate", :start_time => "1:46:43 PM", :end_time => "1:47:44 PM"}, ...]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment