blob: 7af1a824d5c6485d7e9a74b736b6350daf2b3471 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
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
|