aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarald Eilertsen <haraldei@anduin.net>2014-11-14 10:52:40 +0100
committerHarald Eilertsen <haraldei@anduin.net>2014-11-14 10:52:40 +0100
commit0e22855375f10343d77fdcc83b323a992325649f (patch)
tree7a87d94c30a38871fa477ef4f39b19bf9f395b44
parent84dfb2f6a63ad68641c83c72e5fa17671579b296 (diff)
downloadimusician-reports-0e22855375f10343d77fdcc83b323a992325649f.tar.gz
imusician-reports-0e22855375f10343d77fdcc83b323a992325649f.tar.bz2
imusician-reports-0e22855375f10343d77fdcc83b323a992325649f.zip
Make csv-parsing a method.
-rw-r--r--parse_report.rb30
1 files changed, 18 insertions, 12 deletions
diff --git a/parse_report.rb b/parse_report.rb
index b8a2bcc..714c746 100644
--- a/parse_report.rb
+++ b/parse_report.rb
@@ -1,19 +1,23 @@
require 'sale'
require 'csv'
-csv_opts = {
- :col_sep => ";",
- :skip_lines => /^(Notes|The |;)/,
- :headers => true,
- :converters => :all,
-}
-
-sales = []
-
-CSV.foreach(ARGV[0], csv_opts) do |row|
- if row.count > 0
- sales << SalesReporter::Sale.new(row["Date"], row["revenue EUR"], row["quantity"], row["Country"], row["Shop"])
+def parse_csv(csv_file)
+ csv_opts = {
+ :col_sep => ";",
+ :skip_lines => /^(Notes|The |;)/,
+ :headers => true,
+ :converters => :all,
+ }
+
+ sales = []
+
+ CSV.foreach(csv_file, csv_opts) do |row|
+ if row.count > 0
+ sales << SalesReporter::Sale.new(row["Date"], row["revenue EUR"], row["quantity"], row["Country"], row["Shop"])
+ end
end
+
+ sales
end
def load_reports
@@ -22,6 +26,8 @@ def load_reports
end
end
+sales = parse_csv(ARGV[0])
+
load_reports
SalesReporter::Reports::SalesByDate.render(sales)