demo.rb in parseitc-0.1.2 vs demo.rb in parseitc-0.1.3
- old
+ new
@@ -1,17 +1,40 @@
require 'rubygems'
require 'lib/parseitc'
include ParseITC
begin
- report = TransactionParser.new('demo1.txt')
+ report = Parser.new('demo1.txt')
report.add_file('demo2.txt')
- by_country = report.numbers_by_country
- by_country.sort.each {|k, v| puts "#{k}: #{v}"}
- by_date = report.numbers_by_date
- by_date.sort.each {|k, v| puts "#{k}: #{v}"}
- by_royalty_currency = report.numbers_by_price_tier
- by_royalty_currency.sort.each {|k, v| puts "#{k}: #{v}"}
+
+ puts '=' * 20
+ puts "Sales in top 10 countries"
+ report.count_by_country.sort_by{|k,v| v}.reverse[0..9].each do |k, v|
+ puts " #{k}: #{v}"
+ end
+
+ puts
+ puts '=' * 20
+ puts "Sales volume per day"
+ report.count_by_date.sort.each do |k, v|
+ puts " #{k}: #{v}"
+ end
+
+ puts
+ puts '=' * 20
+ puts "Sales by price and date"
+ total = 0
+ report.split_by_date.sort.each do |k1, v1|
+ puts " #{k1}"
+ v1.count_by_price_tier.sort.each do |k2, v2|
+ dollars = ApplePricing[:usd][k2]
+ puts " $ #{dollars.to_f}: #{v2}"
+ total += dollars.to_f * v2
+ end
+ end
+ puts "Revenue: $#{total/7*10} "
+ puts "Profit: $#{total} "
+
rescue Errno::ENOENT
puts "The data file you specified was not found"
rescue Errno::EACCES
puts "The data file you specified is not readable"
end