diff options
Diffstat (limited to 'parse_report.rb')
-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 |