aboutsummaryrefslogblamecommitdiffstats
path: root/parse_report.rb
blob: 7af1a824d5c6485d7e9a74b736b6350daf2b3471 (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

parse_csv(ARGV[0]) do |row|
  sale = SalesReporter::Sale.new(row["Date"], row["revenue EUR"], row["quantity"])
  reports.each { |r| r.add_sale(sale, row) }
end

reports.each do |report|
  report.render
end