aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarald Eilertsen <haraldei@anduin.net>2014-11-14 14:29:06 +0100
committerHarald Eilertsen <haraldei@anduin.net>2014-11-14 14:29:06 +0100
commit1aa812034f41e79d3497a14528bcb66d362c4eb2 (patch)
tree97619853fd5847178225057075eaffbe04723a5e
parent8fd06149ffe3d5790cdcb64d40916210590b03ba (diff)
downloadimusician-reports-1aa812034f41e79d3497a14528bcb66d362c4eb2.tar.gz
imusician-reports-1aa812034f41e79d3497a14528bcb66d362c4eb2.tar.bz2
imusician-reports-1aa812034f41e79d3497a14528bcb66d362c4eb2.zip
Instantiate reports instead of using static methods.
-rw-r--r--lib/reports/sales_by_country.rb2
-rw-r--r--lib/reports/sales_by_date.rb2
-rw-r--r--lib/reports/sales_by_shop.rb2
-rw-r--r--parse_report.rb20
4 files changed, 17 insertions, 9 deletions
diff --git a/lib/reports/sales_by_country.rb b/lib/reports/sales_by_country.rb
index 58f1b15..4017dbf 100644
--- a/lib/reports/sales_by_country.rb
+++ b/lib/reports/sales_by_country.rb
@@ -1,7 +1,7 @@
module SalesReporter
module Reports
class SalesByCountry
- def self.render(sales)
+ def render(sales)
sales_by_country = {}
sales.each do |s|
diff --git a/lib/reports/sales_by_date.rb b/lib/reports/sales_by_date.rb
index 9e623f1..4bc9094 100644
--- a/lib/reports/sales_by_date.rb
+++ b/lib/reports/sales_by_date.rb
@@ -1,7 +1,7 @@
module SalesReporter
module Reports
class SalesByDate
- def self.render(sales)
+ def render(sales)
sales_by_date = {}
sales.each do |s|
diff --git a/lib/reports/sales_by_shop.rb b/lib/reports/sales_by_shop.rb
index 7308b1d..66caf63 100644
--- a/lib/reports/sales_by_shop.rb
+++ b/lib/reports/sales_by_shop.rb
@@ -1,7 +1,7 @@
module SalesReporter
module Reports
class SalesByShop
- def self.render(sales)
+ def render(sales)
sales_by_shop = {}
sales.each do |s|
diff --git a/parse_report.rb b/parse_report.rb
index 2286cc0..9a2340c 100644
--- a/parse_report.rb
+++ b/parse_report.rb
@@ -1,4 +1,4 @@
-require 'sale'
+require_relative 'lib/sale'
require 'csv'
def parse_csv(csv_file)
@@ -13,7 +13,8 @@ def parse_csv(csv_file)
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"])
+ sale = SalesReporter::Sale.new(row["Date"], row["revenue EUR"], row["quantity"], row["Country"], row["Shop"])
+ sales << sale
end
end
@@ -21,15 +22,22 @@ def parse_csv(csv_file)
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
+ end
+
+ reports
end
sales = parse_csv(ARGV[0])
+reports = load_reports
-load_reports
-
-SalesReporter::Reports.constants.each do |report|
- SalesReporter::Reports.const_get(report).render(sales)
+reports.each do |report|
+ report.render(sales)
end