diff options
author | Harald Eilertsen <haraldei@anduin.net> | 2014-11-14 15:35:02 +0100 |
---|---|---|
committer | Harald Eilertsen <haraldei@anduin.net> | 2014-11-14 15:35:02 +0100 |
commit | c4bc044881c05822a66d4f77a4ffad9368235731 (patch) | |
tree | e7676b197b99e3621f209cbdb14b23ca0d46494f | |
parent | 1aa812034f41e79d3497a14528bcb66d362c4eb2 (diff) | |
download | imusician-reports-c4bc044881c05822a66d4f77a4ffad9368235731.tar.gz imusician-reports-c4bc044881c05822a66d4f77a4ffad9368235731.tar.bz2 imusician-reports-c4bc044881c05822a66d4f77a4ffad9368235731.zip |
Refactor code, use blocks instead of returning arrays.
-rw-r--r-- | parse_report.rb | 21 |
1 files changed, 8 insertions, 13 deletions
diff --git a/parse_report.rb b/parse_report.rb index 9a2340c..48b7c71 100644 --- a/parse_report.rb +++ b/parse_report.rb @@ -9,35 +9,30 @@ def parse_csv(csv_file) :converters => :all, } - sales = [] - CSV.foreach(csv_file, csv_opts) do |row| if row.count > 0 - sale = SalesReporter::Sale.new(row["Date"], row["revenue EUR"], row["quantity"], row["Country"], row["Shop"]) - sales << sale + yield row end end - - sales end def load_reports - reports = [] - Dir[File.join('lib', 'reports', '*.rb')].each do |f| require_relative f end - SalesReporter::Reports.constants.each do |report| - reports << SalesReporter::Reports.const_get(report).new + SalesReporter::Reports.constants.map do |report| + SalesReporter::Reports.const_get(report).new end - - reports end -sales = parse_csv(ARGV[0]) reports = load_reports +sales = [] +parse_csv(ARGV[0]) do |row| + sales << SalesReporter::Sale.new(row["Date"], row["revenue EUR"], row["quantity"], row["Country"], row["Shop"]) +end + reports.each do |report| report.render(sales) end |