aboutsummaryrefslogblamecommitdiffstats
path: root/parse_report.rb
blob: 2286cc0ce6e46a98087d13a0dd3a42d6a18002f5 (plain) (tree)
1
2
3

              
 













                                                                                                                     
     

       

   

                                                      
                      


     

                          

            


                                                        
require 'sale'
require 'csv'

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
  Dir[File.join('lib', 'reports', '*.rb')].each do |f|
    require_relative f
  end
end

sales = parse_csv(ARGV[0])

load_reports

SalesReporter::Reports.constants.each do |report|
  SalesReporter::Reports.const_get(report).render(sales)
end