Created
February 9, 2011 06:23
-
-
Save starkcoffee/818018 to your computer and use it in GitHub Desktop.
A script to analyse your vodafone bill (if you download the bill as csv)
This file contains 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
if ARGV.length != 1 | |
p "Provide a vodafone csv file you donkey!" | |
exit 666 | |
end | |
file = open(ARGV[0], 'r').read | |
# isolate the csv part of the vodafone data file... multiline regex match FTW!!! | |
BEGIN_MARKER="Call details for.*?\n" | |
END_MARKER=",,,,," | |
regex = /#{BEGIN_MARKER}(.*?)#{END_MARKER}/m | |
csv_lines = regex.match(file)[1].lines.to_a | |
records = csv_lines.map {|line| line.chop!.split ','} | |
headers = records.shift | |
# turn each array of comma separated values into a hash using the headers. weeeee!!! | |
records.map! do |record| | |
record_hash = {} | |
headers.zip(record) { |heading, value| record_hash[heading]=value } | |
record_hash | |
end | |
# analyse away!! | |
call_charge_total = records.inject(0) { |sum, record| sum += record["Call Charge"].to_f } | |
p call_charge_total | |
# the bill is correct. :( |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment