aboutsummaryrefslogblamecommitdiffstats
path: root/parse_report.rb
blob: 48b7c717c6ab3ea07fec8193c87c0ff101bc0d5f (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
                           
             
 







                                     

                                          
               
       


     

                                                      
                      
     
 

                                                  
     

   
                      
 




                                                                                                                 

                        
   
require_relative 'lib/sale'
require 'csv'

def parse_csv(csv_file)
  csv_opts = {
    :col_sep => ";",
    :skip_lines => /^(Notes|The |;)/,
    :headers => true,
    :converters => :all,
  }

  CSV.foreach(csv_file, csv_opts) do |row|
    if row.count > 0
      yield row
    end
  end
end

def load_reports
  Dir[File.join('lib', 'reports', '*.rb')].each do |f|
    require_relative f
  end

  SalesReporter::Reports.constants.map do |report|
    SalesReporter::Reports.const_get(report).new
  end
end

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