From eac6cfa96cf1e0849284cc49c667bfb2eeb913c0 Mon Sep 17 00:00:00 2001 From: Jenna Nichols Date: Mon, 19 Oct 2015 15:35:43 -0700 Subject: [PATCH 01/47] removed unnecessary parentheses --- spec/far_mar/market_spec.rb | 2 +- spec/far_mar/product_spec.rb | 2 +- spec/far_mar/sale_spec.rb | 2 +- spec/far_mar/vendor_spec.rb | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/spec/far_mar/market_spec.rb b/spec/far_mar/market_spec.rb index 65cb89c4..3e8ffe3a 100644 --- a/spec/far_mar/market_spec.rb +++ b/spec/far_mar/market_spec.rb @@ -3,7 +3,7 @@ describe FarMar::Market do before :each do - @market = FarMar::Market.new() + @market = FarMar::Market.new end describe ".new" do diff --git a/spec/far_mar/product_spec.rb b/spec/far_mar/product_spec.rb index 0ca4dab7..2dc48806 100644 --- a/spec/far_mar/product_spec.rb +++ b/spec/far_mar/product_spec.rb @@ -3,7 +3,7 @@ describe FarMar::Product do before :each do - @product = FarMar::Product.new() + @product = FarMar::Product.new end describe ".new" do diff --git a/spec/far_mar/sale_spec.rb b/spec/far_mar/sale_spec.rb index 8fd6eae1..0a7c35e6 100644 --- a/spec/far_mar/sale_spec.rb +++ b/spec/far_mar/sale_spec.rb @@ -3,7 +3,7 @@ describe FarMar::Sale do before :each do - @sale = FarMar::Sale.new() + @sale = FarMar::Sale.new end describe ".new" do diff --git a/spec/far_mar/vendor_spec.rb b/spec/far_mar/vendor_spec.rb index 60ea67df..f8bcd1c1 100644 --- a/spec/far_mar/vendor_spec.rb +++ b/spec/far_mar/vendor_spec.rb @@ -3,7 +3,7 @@ describe FarMar::Vendor do before :each do - @vendor = FarMar::Vendor.new() + @vendor = FarMar::Vendor.new end describe ".new" do From 67425558f73612d8317ad065cdaf64474386185d Mon Sep 17 00:00:00 2001 From: Jenna Nichols Date: Mon, 19 Oct 2015 16:34:20 -0700 Subject: [PATCH 02/47] added self.all tests and code --- lib/far_mar/market.rb | 4 ++++ lib/far_mar/product.rb | 4 ++++ lib/far_mar/sale.rb | 4 ++++ lib/far_mar/vendor.rb | 4 ++++ spec/far_mar/market_spec.rb | 19 +++++++++++++++---- spec/far_mar/product_spec.rb | 19 +++++++++++++++---- spec/far_mar/sale_spec.rb | 19 +++++++++++++++---- spec/far_mar/vendor_spec.rb | 19 +++++++++++++++---- 8 files changed, 76 insertions(+), 16 deletions(-) diff --git a/lib/far_mar/market.rb b/lib/far_mar/market.rb index c93b3797..e62f0184 100644 --- a/lib/far_mar/market.rb +++ b/lib/far_mar/market.rb @@ -1,6 +1,10 @@ module FarMar class Market + def self.all + markets = CSV.read("./support/markets.csv") + return markets + end end end diff --git a/lib/far_mar/product.rb b/lib/far_mar/product.rb index 7ecaff61..46f63d7e 100644 --- a/lib/far_mar/product.rb +++ b/lib/far_mar/product.rb @@ -1,6 +1,10 @@ module FarMar class Product + def self.all + products = CSV.read("./support/products.csv") + return products + end end end diff --git a/lib/far_mar/sale.rb b/lib/far_mar/sale.rb index 3c854204..fbcd24e0 100644 --- a/lib/far_mar/sale.rb +++ b/lib/far_mar/sale.rb @@ -1,6 +1,10 @@ module FarMar class Sale + def self.all + sales = CSV.read("./support/sales.csv") + return sales + end end end diff --git a/lib/far_mar/vendor.rb b/lib/far_mar/vendor.rb index e028114c..9b40a3bb 100644 --- a/lib/far_mar/vendor.rb +++ b/lib/far_mar/vendor.rb @@ -1,6 +1,10 @@ module FarMar class Vendor + def self.all + vendors = CSV.read("./support/vendors.csv") + return vendors + end end end diff --git a/spec/far_mar/market_spec.rb b/spec/far_mar/market_spec.rb index 3e8ffe3a..6e33e14d 100644 --- a/spec/far_mar/market_spec.rb +++ b/spec/far_mar/market_spec.rb @@ -2,15 +2,26 @@ describe FarMar do describe FarMar::Market do - before :each do - @market = FarMar::Market.new - end - describe ".new" do + before :each do + @market = FarMar::Market.new + end it "creates a new instance of the Market class" do expect(@market).to be_an_instance_of(FarMar::Market) end end + describe ".all" do + before :each do + @markets = CSV.read("./support/markets.csv") + end + it "returns an array" do + expect(FarMar::Market.all).to be_an(Array) + end + it "returns an array with the vendor info" do + expect(FarMar::Market.all.length).to eq(@markets.size) + end + end + end end diff --git a/spec/far_mar/product_spec.rb b/spec/far_mar/product_spec.rb index 2dc48806..986451ad 100644 --- a/spec/far_mar/product_spec.rb +++ b/spec/far_mar/product_spec.rb @@ -2,15 +2,26 @@ describe FarMar do describe FarMar::Product do - before :each do - @product = FarMar::Product.new - end - describe ".new" do + before :each do + @product = FarMar::Product.new + end it "creates a new instance of the Product class" do expect(@product).to be_an_instance_of(FarMar::Product) end end + describe ".all" do + before :each do + @products = CSV.read("./support/products.csv") + end + it "returns an array" do + expect(FarMar::Product.all).to be_an(Array) + end + it "returns an array with the vendor info" do + expect(FarMar::Product.all.length).to eq(@products.size) + end + end + end end diff --git a/spec/far_mar/sale_spec.rb b/spec/far_mar/sale_spec.rb index 0a7c35e6..fca314d8 100644 --- a/spec/far_mar/sale_spec.rb +++ b/spec/far_mar/sale_spec.rb @@ -2,15 +2,26 @@ describe FarMar do describe FarMar::Sale do - before :each do - @sale = FarMar::Sale.new - end - describe ".new" do + before :each do + @sale = FarMar::Sale.new + end it "creates a new instance of the Sale class" do expect(@sale).to be_an_instance_of(FarMar::Sale) end end + describe ".all" do + before :each do + @sales = CSV.read("./support/sales.csv") + end + it "returns an array" do + expect(FarMar::Sale.all).to be_an(Array) + end + it "returns an array with the vendor info" do + expect(FarMar::Sale.all.length).to eq(@sales.size) + end + end + end end diff --git a/spec/far_mar/vendor_spec.rb b/spec/far_mar/vendor_spec.rb index f8bcd1c1..b160a417 100644 --- a/spec/far_mar/vendor_spec.rb +++ b/spec/far_mar/vendor_spec.rb @@ -2,15 +2,26 @@ describe FarMar do describe FarMar::Vendor do - before :each do - @vendor = FarMar::Vendor.new - end - describe ".new" do + before :each do + @vendor = FarMar::Vendor.new + end it "creates a new instance of the Vendor class" do expect(@vendor).to be_an_instance_of(FarMar::Vendor) end end + describe ".all" do + before :each do + @vendors = CSV.read("./support/vendors.csv") + end + it "returns an array" do + expect(FarMar::Vendor.all).to be_an(Array) + end + it "returns an array with the vendor info" do + expect(FarMar::Vendor.all.length).to eq(@vendors.size) + end + end + end end From 7e9b73eda633b8432c0402999411412a9c5881d5 Mon Sep 17 00:00:00 2001 From: Jenna Nichols Date: Tue, 20 Oct 2015 16:23:03 -0700 Subject: [PATCH 03/47] updated initialize method/tests for Market --- lib/far_mar/market.rb | 20 ++++++++++++++++++-- spec/far_mar/market_spec.rb | 16 +++++++++++++--- 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/lib/far_mar/market.rb b/lib/far_mar/market.rb index e62f0184..58e42c76 100644 --- a/lib/far_mar/market.rb +++ b/lib/far_mar/market.rb @@ -1,9 +1,25 @@ module FarMar class Market + attr_reader :id + + def initialize(market_info) + @id = market_info[0] + @name = market_info[1] + @address = market_info[2] + @city = market_info[3] + @county = market_info[4] + @state = market_info[5] + @zip = market_info[6] + end + def self.all - markets = CSV.read("./support/markets.csv") - return markets + market_array = [] + CSV.read("./support/markets.csv").each do |market| + new_market = FarMar::Market.new(market) + market_array.push(new_market) + end + return market_array end end diff --git a/spec/far_mar/market_spec.rb b/spec/far_mar/market_spec.rb index 6e33e14d..933a1590 100644 --- a/spec/far_mar/market_spec.rb +++ b/spec/far_mar/market_spec.rb @@ -2,13 +2,17 @@ describe FarMar do describe FarMar::Market do - describe ".new" do + describe "#initialize" do before :each do - @market = FarMar::Market.new + market_info = [1,"People's Co-op Farmers Market","30th and Burnside","Portland","Multnomah","Oregon","97202"] + @market = FarMar::Market.new(market_info) end it "creates a new instance of the Market class" do expect(@market).to be_an_instance_of(FarMar::Market) end + it "retrieves the market ID from the market info array" do + expect(@market.id).to eq(1) + end end describe ".all" do @@ -18,9 +22,15 @@ it "returns an array" do expect(FarMar::Market.all).to be_an(Array) end - it "returns an array with the vendor info" do + it "returns an array with all the markets" do expect(FarMar::Market.all.length).to eq(@markets.size) end + it "contains instances of the Market class" do + market_total = FarMar::Market.all.length + expect(FarMar::Market.all[0]).to be_an_instance_of(FarMar::Market) + expect(FarMar::Market.all[market_total - 1]).to be_an_instance_of(FarMar::Market) + expect(FarMar::Market.all[market_total]).to be nil + end end end From 3681850e35c72ab680ffcfc06c1012e8ef20c8ba Mon Sep 17 00:00:00 2001 From: Jenna Nichols Date: Tue, 20 Oct 2015 16:29:06 -0700 Subject: [PATCH 04/47] added self.all methods/tests for Vendor class --- lib/far_mar/vendor.rb | 16 ++++++++++++++-- spec/far_mar/vendor_spec.rb | 16 +++++++++++++--- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/lib/far_mar/vendor.rb b/lib/far_mar/vendor.rb index 9b40a3bb..4f194b15 100644 --- a/lib/far_mar/vendor.rb +++ b/lib/far_mar/vendor.rb @@ -1,9 +1,21 @@ module FarMar class Vendor + attr_reader :id, :market_id + + def initialize(vendor_info) + @id = vendor_info[0] + @name = vendor_info[1] + @number_of_employees = vendor_info[2] + @market_id = vendor_info[3] + end def self.all - vendors = CSV.read("./support/vendors.csv") - return vendors + vendor_array = [] + CSV.read("./support/vendors.csv").each do |vendor| + new_vendor = FarMar::Vendor.new(vendor) + vendor_array.push(new_vendor) + end + return vendor_array end end diff --git a/spec/far_mar/vendor_spec.rb b/spec/far_mar/vendor_spec.rb index b160a417..7368d148 100644 --- a/spec/far_mar/vendor_spec.rb +++ b/spec/far_mar/vendor_spec.rb @@ -2,13 +2,17 @@ describe FarMar do describe FarMar::Vendor do - describe ".new" do + describe "#initialize" do before :each do - @vendor = FarMar::Vendor.new + vendor_info = [1,"Feil-Farrell",8,1] + @vendor = FarMar::Vendor.new(vendor_info) end it "creates a new instance of the Vendor class" do expect(@vendor).to be_an_instance_of(FarMar::Vendor) end + it "retrieves the vendor ID from the vendor info array" do + expect(@vendor.id).to eq(1) + end end describe ".all" do @@ -18,9 +22,15 @@ it "returns an array" do expect(FarMar::Vendor.all).to be_an(Array) end - it "returns an array with the vendor info" do + it "returns an array with all the vendors" do expect(FarMar::Vendor.all.length).to eq(@vendors.size) end + it "contains instances of the Vendor class" do + vendor_total = FarMar::Vendor.all.length + expect(FarMar::Vendor.all[0]).to be_an_instance_of(FarMar::Vendor) + expect(FarMar::Vendor.all[vendor_total - 1]).to be_an_instance_of(FarMar::Vendor) + expect(FarMar::Vendor.all[vendor_total]).to be nil + end end end From aad588a7dbb9e066cbbdd2b7dc82bc1d3c14d128 Mon Sep 17 00:00:00 2001 From: Jenna Nichols Date: Tue, 20 Oct 2015 16:33:01 -0700 Subject: [PATCH 05/47] added self.all method/tests for Product class --- lib/far_mar/product.rb | 15 +++++++++++++-- spec/far_mar/product_spec.rb | 16 +++++++++++++--- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/lib/far_mar/product.rb b/lib/far_mar/product.rb index 46f63d7e..2985e55c 100644 --- a/lib/far_mar/product.rb +++ b/lib/far_mar/product.rb @@ -1,9 +1,20 @@ module FarMar class Product + attr_reader :id, :vendor_id + + def initialize(product_info) + @id = product_info[0] + @name = product_info[1] + @vendor_id = product_info[2] + end def self.all - products = CSV.read("./support/products.csv") - return products + product_array = [] + CSV.read("./support/products.csv").each do |product| + new_product = FarMar::Product.new(product) + product_array.push(new_product) + end + return product_array end end diff --git a/spec/far_mar/product_spec.rb b/spec/far_mar/product_spec.rb index 986451ad..8df31b3b 100644 --- a/spec/far_mar/product_spec.rb +++ b/spec/far_mar/product_spec.rb @@ -2,13 +2,17 @@ describe FarMar do describe FarMar::Product do - describe ".new" do + describe "#initialize" do before :each do - @product = FarMar::Product.new + product_info = [1,"Dry Beets",1] + @product = FarMar::Product.new(product_info) end it "creates a new instance of the Product class" do expect(@product).to be_an_instance_of(FarMar::Product) end + it "retrieves the product ID from the product info array" do + expect(@product.id).to eq(1) + end end describe ".all" do @@ -18,9 +22,15 @@ it "returns an array" do expect(FarMar::Product.all).to be_an(Array) end - it "returns an array with the vendor info" do + it "returns an array with all the products" do expect(FarMar::Product.all.length).to eq(@products.size) end + it "contains instances of the Product class" do + vendor_total = FarMar::Product.all.length + expect(FarMar::Product.all[0]).to be_an_instance_of(FarMar::Product) + expect(FarMar::Product.all[vendor_total - 1]).to be_an_instance_of(FarMar::Product) + expect(FarMar::Product.all[vendor_total]).to be nil + end end end From 9a6162c04d0bac60005b0d355790d7922a6d6919 Mon Sep 17 00:00:00 2001 From: Jenna Nichols Date: Tue, 20 Oct 2015 16:38:55 -0700 Subject: [PATCH 06/47] updated vendor with self.all --- lib/far_mar/sale.rb | 18 +++++++++++++++--- spec/far_mar/sale_spec.rb | 16 +++++++++++++--- 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/lib/far_mar/sale.rb b/lib/far_mar/sale.rb index fbcd24e0..969a82f9 100644 --- a/lib/far_mar/sale.rb +++ b/lib/far_mar/sale.rb @@ -1,10 +1,22 @@ module FarMar class Sale + attr_reader :id, :vendor_id, :product_id - def self.all - sales = CSV.read("./support/sales.csv") - return sales + def initialize(sale_info) + @id = sale_info[0] + @amount = sale_info[1] + @purchase_time = sale_info[2] + @vendor_id = sale_info[3] + @product_id = sale_info[4] end + def self.all + sale_array = [] + CSV.read("./support/sales.csv").each do |sale| + new_sale = FarMar::Sale.new(sale) + sale_array.push(new_sale) + end + return sale_array + end end end diff --git a/spec/far_mar/sale_spec.rb b/spec/far_mar/sale_spec.rb index fca314d8..6bd52a4e 100644 --- a/spec/far_mar/sale_spec.rb +++ b/spec/far_mar/sale_spec.rb @@ -2,13 +2,17 @@ describe FarMar do describe FarMar::Sale do - describe ".new" do + describe "#initialize" do before :each do - @sale = FarMar::Sale.new + sale_info = [1,9290,"2013-11-07 04:34:56 -0800",1,1] + @sale = FarMar::Sale.new(sale_info) end it "creates a new instance of the Sale class" do expect(@sale).to be_an_instance_of(FarMar::Sale) end + it "retrieves the sale ID from the sale info array" do + expect(@sale.id).to eq(1) + end end describe ".all" do @@ -18,9 +22,15 @@ it "returns an array" do expect(FarMar::Sale.all).to be_an(Array) end - it "returns an array with the vendor info" do + it "returns an array with all the sales" do expect(FarMar::Sale.all.length).to eq(@sales.size) end + it "contains instances of the Sale class" do + vendor_total = FarMar::Sale.all.length + expect(FarMar::Sale.all[0]).to be_an_instance_of(FarMar::Sale) + expect(FarMar::Sale.all[vendor_total - 1]).to be_an_instance_of(FarMar::Sale) + expect(FarMar::Sale.all[vendor_total]).to be nil + end end end From 46cfc74ba1fd266947ebe04fa220ac5e90292b87 Mon Sep 17 00:00:00 2001 From: Jenna Nichols Date: Tue, 20 Oct 2015 16:51:34 -0700 Subject: [PATCH 07/47] updated integers and csv tests --- lib/far_mar/market.rb | 2 +- lib/far_mar/product.rb | 4 ++-- lib/far_mar/sale.rb | 8 ++++---- lib/far_mar/vendor.rb | 6 +++--- spec/far_mar/market_spec.rb | 2 +- spec/far_mar/product_spec.rb | 2 +- spec/far_mar/sale_spec.rb | 2 +- spec/far_mar/vendor_spec.rb | 2 +- 8 files changed, 14 insertions(+), 14 deletions(-) diff --git a/lib/far_mar/market.rb b/lib/far_mar/market.rb index 58e42c76..421b452b 100644 --- a/lib/far_mar/market.rb +++ b/lib/far_mar/market.rb @@ -3,7 +3,7 @@ class Market attr_reader :id def initialize(market_info) - @id = market_info[0] + @id = market_info[0].to_i @name = market_info[1] @address = market_info[2] @city = market_info[3] diff --git a/lib/far_mar/product.rb b/lib/far_mar/product.rb index 2985e55c..d98cc631 100644 --- a/lib/far_mar/product.rb +++ b/lib/far_mar/product.rb @@ -3,9 +3,9 @@ class Product attr_reader :id, :vendor_id def initialize(product_info) - @id = product_info[0] + @id = product_info[0].to_i @name = product_info[1] - @vendor_id = product_info[2] + @vendor_id = product_info[2].to_i end def self.all diff --git a/lib/far_mar/sale.rb b/lib/far_mar/sale.rb index 969a82f9..dd3da24d 100644 --- a/lib/far_mar/sale.rb +++ b/lib/far_mar/sale.rb @@ -3,11 +3,11 @@ class Sale attr_reader :id, :vendor_id, :product_id def initialize(sale_info) - @id = sale_info[0] - @amount = sale_info[1] + @id = sale_info[0].to_i + @amount = sale_info[1].to_i @purchase_time = sale_info[2] - @vendor_id = sale_info[3] - @product_id = sale_info[4] + @vendor_id = sale_info[3].to_i + @product_id = sale_info[4].to_i end def self.all diff --git a/lib/far_mar/vendor.rb b/lib/far_mar/vendor.rb index 4f194b15..3f26bd43 100644 --- a/lib/far_mar/vendor.rb +++ b/lib/far_mar/vendor.rb @@ -3,10 +3,10 @@ class Vendor attr_reader :id, :market_id def initialize(vendor_info) - @id = vendor_info[0] + @id = vendor_info[0].to_i @name = vendor_info[1] - @number_of_employees = vendor_info[2] - @market_id = vendor_info[3] + @number_of_employees = vendor_info[2].to_i + @market_id = vendor_info[3].to_i end def self.all diff --git a/spec/far_mar/market_spec.rb b/spec/far_mar/market_spec.rb index 933a1590..6c32ffc0 100644 --- a/spec/far_mar/market_spec.rb +++ b/spec/far_mar/market_spec.rb @@ -4,7 +4,7 @@ describe "#initialize" do before :each do - market_info = [1,"People's Co-op Farmers Market","30th and Burnside","Portland","Multnomah","Oregon","97202"] + market_info = CSV.open("./support/markets.csv", 'r') { |csv| csv.first } @market = FarMar::Market.new(market_info) end it "creates a new instance of the Market class" do diff --git a/spec/far_mar/product_spec.rb b/spec/far_mar/product_spec.rb index 8df31b3b..840cd1bd 100644 --- a/spec/far_mar/product_spec.rb +++ b/spec/far_mar/product_spec.rb @@ -4,7 +4,7 @@ describe "#initialize" do before :each do - product_info = [1,"Dry Beets",1] + product_info = CSV.open("./support/products.csv", 'r') { |csv| csv.first } @product = FarMar::Product.new(product_info) end it "creates a new instance of the Product class" do diff --git a/spec/far_mar/sale_spec.rb b/spec/far_mar/sale_spec.rb index 6bd52a4e..da86e4a3 100644 --- a/spec/far_mar/sale_spec.rb +++ b/spec/far_mar/sale_spec.rb @@ -4,7 +4,7 @@ describe "#initialize" do before :each do - sale_info = [1,9290,"2013-11-07 04:34:56 -0800",1,1] + sale_info = CSV.open("./support/sales.csv", 'r') { |csv| csv.first } @sale = FarMar::Sale.new(sale_info) end it "creates a new instance of the Sale class" do diff --git a/spec/far_mar/vendor_spec.rb b/spec/far_mar/vendor_spec.rb index 7368d148..c05d57ea 100644 --- a/spec/far_mar/vendor_spec.rb +++ b/spec/far_mar/vendor_spec.rb @@ -4,7 +4,7 @@ describe "#initialize" do before :each do - vendor_info = [1,"Feil-Farrell",8,1] + vendor_info = CSV.open("./support/vendors.csv", 'r') { |csv| csv.first } @vendor = FarMar::Vendor.new(vendor_info) end it "creates a new instance of the Vendor class" do From 3eb24ebd2308c1e3bf6c0c1e6cc0e85e3b692df4 Mon Sep 17 00:00:00 2001 From: Jenna Nichols Date: Tue, 20 Oct 2015 17:01:53 -0700 Subject: [PATCH 08/47] updated purchase time formatting --- lib/far_mar/sale.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/far_mar/sale.rb b/lib/far_mar/sale.rb index dd3da24d..41e4e5fc 100644 --- a/lib/far_mar/sale.rb +++ b/lib/far_mar/sale.rb @@ -5,7 +5,7 @@ class Sale def initialize(sale_info) @id = sale_info[0].to_i @amount = sale_info[1].to_i - @purchase_time = sale_info[2] + @purchase_time = DateTime.strptime(sale_info[2], "%Y-%m-%d %H:%M:%S %z") @vendor_id = sale_info[3].to_i @product_id = sale_info[4].to_i end From 48623d5b12599e05c6d2e76a96913a166731fcfe Mon Sep 17 00:00:00 2001 From: Jenna Nichols Date: Wed, 21 Oct 2015 10:08:56 -0700 Subject: [PATCH 09/47] code and test for self.find methods --- lib/far_mar/market.rb | 6 ++++++ lib/far_mar/product.rb | 7 +++++++ lib/far_mar/sale.rb | 9 ++++++++- lib/far_mar/vendor.rb | 6 ++++++ spec/far_mar/market_spec.rb | 12 ++++++++++++ spec/far_mar/product_spec.rb | 12 ++++++++++++ spec/far_mar/sale_spec.rb | 12 ++++++++++++ spec/far_mar/vendor_spec.rb | 12 ++++++++++++ 8 files changed, 75 insertions(+), 1 deletion(-) diff --git a/lib/far_mar/market.rb b/lib/far_mar/market.rb index 421b452b..2fe0bf2e 100644 --- a/lib/far_mar/market.rb +++ b/lib/far_mar/market.rb @@ -22,5 +22,11 @@ def self.all return market_array end + def self.find(id) + FarMar::Market.all.find do |market| + market.id == id + end + end + end end diff --git a/lib/far_mar/product.rb b/lib/far_mar/product.rb index d98cc631..096d3a07 100644 --- a/lib/far_mar/product.rb +++ b/lib/far_mar/product.rb @@ -17,5 +17,12 @@ def self.all return product_array end + def self.find(id) + FarMar::Product.all.find do |product| + product.id == id + end + end + + end end diff --git a/lib/far_mar/sale.rb b/lib/far_mar/sale.rb index 41e4e5fc..ad9be327 100644 --- a/lib/far_mar/sale.rb +++ b/lib/far_mar/sale.rb @@ -5,7 +5,7 @@ class Sale def initialize(sale_info) @id = sale_info[0].to_i @amount = sale_info[1].to_i - @purchase_time = DateTime.strptime(sale_info[2], "%Y-%m-%d %H:%M:%S %z") + @purchase_time = DateTime.strptime(sale_info[2], "%Y-%m-%d %H:%M:%S %z") @vendor_id = sale_info[3].to_i @product_id = sale_info[4].to_i end @@ -18,5 +18,12 @@ def self.all end return sale_array end + + def self.find(id) + FarMar::Sale.all.find do |sale| + sale.id == id + end + end + end end diff --git a/lib/far_mar/vendor.rb b/lib/far_mar/vendor.rb index 3f26bd43..523722bb 100644 --- a/lib/far_mar/vendor.rb +++ b/lib/far_mar/vendor.rb @@ -18,5 +18,11 @@ def self.all return vendor_array end + def self.find(id) + FarMar::Vendor.all.find do |vendor| + vendor.id == id + end + end + end end diff --git a/spec/far_mar/market_spec.rb b/spec/far_mar/market_spec.rb index 6c32ffc0..d7a9c355 100644 --- a/spec/far_mar/market_spec.rb +++ b/spec/far_mar/market_spec.rb @@ -31,6 +31,18 @@ expect(FarMar::Market.all[market_total - 1]).to be_an_instance_of(FarMar::Market) expect(FarMar::Market.all[market_total]).to be nil end + + describe ".find(id)" do + before :each do + @id = rand(1..500) + end + it "returns an instance of Market" do + expect(FarMar::Market.find(@id)).to be_an_instance_of(FarMar::Market) + end + it "returns the Market with the matching id" do + expect(FarMar::Market.find(@id).id).to eq(@id) + end + end end end diff --git a/spec/far_mar/product_spec.rb b/spec/far_mar/product_spec.rb index 840cd1bd..b3ebc55c 100644 --- a/spec/far_mar/product_spec.rb +++ b/spec/far_mar/product_spec.rb @@ -33,5 +33,17 @@ end end + describe ".find(id)" do + before :each do + @id = rand(1..8193) + end + it "returns an instance of Product" do + expect(FarMar::Product.find(@id)).to be_an_instance_of(FarMar::Product) + end + it "returns the Product with the matching id" do + expect(FarMar::Product.find(@id).id).to eq(@id) + end + end + end end diff --git a/spec/far_mar/sale_spec.rb b/spec/far_mar/sale_spec.rb index da86e4a3..b8956ee6 100644 --- a/spec/far_mar/sale_spec.rb +++ b/spec/far_mar/sale_spec.rb @@ -33,5 +33,17 @@ end end + describe ".find(id)" do + before :each do + @id = rand(1..12001) + end + it "returns an instance of Sale" do + expect(FarMar::Sale.find(@id)).to be_an_instance_of(FarMar::Sale) + end + it "returns the Sale with the matching id" do + expect(FarMar::Sale.find(@id).id).to eq(@id) + end + end + end end diff --git a/spec/far_mar/vendor_spec.rb b/spec/far_mar/vendor_spec.rb index c05d57ea..5b73683d 100644 --- a/spec/far_mar/vendor_spec.rb +++ b/spec/far_mar/vendor_spec.rb @@ -33,5 +33,17 @@ end end + describe ".find(id)" do + before :each do + @id = rand(1..2690) + end + it "returns an instance of Vendor" do + expect(FarMar::Vendor.find(@id)).to be_an_instance_of(FarMar::Vendor) + end + it "returns the Vendor with the matching id" do + expect(FarMar::Vendor.find(@id).id).to eq(@id) + end + end + end end From c112d1f7e28e34e3054be32b930304b02856f55b Mon Sep 17 00:00:00 2001 From: Jenna Nichols Date: Wed, 21 Oct 2015 10:30:16 -0700 Subject: [PATCH 10/47] tests and code for vendors method in Market class --- lib/far_mar/market.rb | 7 +++++++ spec/far_mar/market_spec.rb | 13 +++++++++++++ 2 files changed, 20 insertions(+) diff --git a/lib/far_mar/market.rb b/lib/far_mar/market.rb index 2fe0bf2e..55dff745 100644 --- a/lib/far_mar/market.rb +++ b/lib/far_mar/market.rb @@ -28,5 +28,12 @@ def self.find(id) end end + def vendors + vendors = FarMar::Vendor.all.find_all do |vendor| + vendor.market_id == self.id + end + return vendors + end + end end diff --git a/spec/far_mar/market_spec.rb b/spec/far_mar/market_spec.rb index d7a9c355..77ec27a5 100644 --- a/spec/far_mar/market_spec.rb +++ b/spec/far_mar/market_spec.rb @@ -43,6 +43,19 @@ expect(FarMar::Market.find(@id).id).to eq(@id) end end + + describe "#vendors" do + before :each do + market_info = CSV.open("./support/markets.csv", 'r') { |csv| csv.first } + @market = FarMar::Market.new(market_info) + end + it "returns a collection" do + expect(@market.vendors).to be_an(Array) + end + it "returns instances of Vendors" do + expect(@market.vendors[0]).to be_an_instance_of(FarMar::Vendor) if @market.vendors.length > 0 + end + end end end From 2386dba7cba64afbfcded8e7045fb0d894b5c50c Mon Sep 17 00:00:00 2001 From: Jenna Nichols Date: Wed, 21 Oct 2015 10:35:24 -0700 Subject: [PATCH 11/47] market method for Vendor class --- lib/far_mar/vendor.rb | 6 ++++++ spec/far_mar/vendor_spec.rb | 13 +++++++++++++ 2 files changed, 19 insertions(+) diff --git a/lib/far_mar/vendor.rb b/lib/far_mar/vendor.rb index 523722bb..be10ef93 100644 --- a/lib/far_mar/vendor.rb +++ b/lib/far_mar/vendor.rb @@ -24,5 +24,11 @@ def self.find(id) end end + def market + FarMar::Market.all.find do |market| + market.id == self.market_id + end + end + end end diff --git a/spec/far_mar/vendor_spec.rb b/spec/far_mar/vendor_spec.rb index 5b73683d..b604aab2 100644 --- a/spec/far_mar/vendor_spec.rb +++ b/spec/far_mar/vendor_spec.rb @@ -45,5 +45,18 @@ end end + describe "#market" do + before :each do + vendor_info = CSV.open("./support/vendors.csv", 'r') { |csv| csv.first } + @vendor = FarMar::Vendor.new(vendor_info) + end + it "returns an instance of the Market class" do + expect(@vendor.market).to be_an_instance_of(FarMar::Market) + end + it "returns the Market with the matching id" do + expect(@vendor.market_id).to eq(@vendor.market.id) + end + end + end end From 354e72fd5b254bc0efdaca8a1f2c23922a16a925 Mon Sep 17 00:00:00 2001 From: Jenna Nichols Date: Wed, 21 Oct 2015 10:39:44 -0700 Subject: [PATCH 12/47] products method for Vendor class --- lib/far_mar/vendor.rb | 7 +++++++ spec/far_mar/vendor_spec.rb | 13 +++++++++++++ 2 files changed, 20 insertions(+) diff --git a/lib/far_mar/vendor.rb b/lib/far_mar/vendor.rb index be10ef93..6c0169bf 100644 --- a/lib/far_mar/vendor.rb +++ b/lib/far_mar/vendor.rb @@ -30,5 +30,12 @@ def market end end + def products + products = FarMar::Product.all.find_all do |product| + product.vendor_id == self.id + end + return products + end + end end diff --git a/spec/far_mar/vendor_spec.rb b/spec/far_mar/vendor_spec.rb index b604aab2..9300bbfe 100644 --- a/spec/far_mar/vendor_spec.rb +++ b/spec/far_mar/vendor_spec.rb @@ -58,5 +58,18 @@ end end + describe "#products" do + before :each do + vendor_info = CSV.open("./support/vendors.csv", 'r') { |csv| csv.first } + @vendor = FarMar::Vendor.new(vendor_info) + end + it "returns a collection" do + expect(@vendor.products).to be_an(Array) + end + it "returns instances of Products" do + expect(@vendor.products[0]).to be_an_instance_of(FarMar::Product) if @vendor.products.length > 0 + end + end + end end From 3b33512c330e8d18c70e1a05b9b9c71e9dc4fa7e Mon Sep 17 00:00:00 2001 From: Jenna Nichols Date: Wed, 21 Oct 2015 10:42:34 -0700 Subject: [PATCH 13/47] sales method for Vendor class --- lib/far_mar/vendor.rb | 7 +++++++ spec/far_mar/vendor_spec.rb | 13 +++++++++++++ 2 files changed, 20 insertions(+) diff --git a/lib/far_mar/vendor.rb b/lib/far_mar/vendor.rb index 6c0169bf..a0e9681d 100644 --- a/lib/far_mar/vendor.rb +++ b/lib/far_mar/vendor.rb @@ -37,5 +37,12 @@ def products return products end + def sales + sales = FarMar::Sale.all.find_all do |sale| + sale.vendor_id == self.id + end + return sales + end + end end diff --git a/spec/far_mar/vendor_spec.rb b/spec/far_mar/vendor_spec.rb index 9300bbfe..28be5f9e 100644 --- a/spec/far_mar/vendor_spec.rb +++ b/spec/far_mar/vendor_spec.rb @@ -71,5 +71,18 @@ end end + describe "#sales" do + before :each do + vendor_info = CSV.open("./support/vendors.csv", 'r') { |csv| csv.first } + @vendor = FarMar::Vendor.new(vendor_info) + end + it "returns a collection" do + expect(@vendor.sales).to be_an(Array) + end + it "returns instances of Sales" do + expect(@vendor.sales[0]).to be_an_instance_of(FarMar::Sale) if @vendor.sales.length > 0 + end + end + end end From 43e48c1af243a106fb85bd467460bb223b51e023 Mon Sep 17 00:00:00 2001 From: Jenna Nichols Date: Wed, 21 Oct 2015 13:43:56 -0700 Subject: [PATCH 14/47] revenue method for Vendor class --- lib/far_mar/sale.rb | 2 +- lib/far_mar/vendor.rb | 9 +++++++++ spec/far_mar/vendor_spec.rb | 30 ++++++++++++++---------------- 3 files changed, 24 insertions(+), 17 deletions(-) diff --git a/lib/far_mar/sale.rb b/lib/far_mar/sale.rb index ad9be327..32cdd043 100644 --- a/lib/far_mar/sale.rb +++ b/lib/far_mar/sale.rb @@ -1,6 +1,6 @@ module FarMar class Sale - attr_reader :id, :vendor_id, :product_id + attr_reader :id, :vendor_id, :product_id, :amount def initialize(sale_info) @id = sale_info[0].to_i diff --git a/lib/far_mar/vendor.rb b/lib/far_mar/vendor.rb index a0e9681d..7dda7a1b 100644 --- a/lib/far_mar/vendor.rb +++ b/lib/far_mar/vendor.rb @@ -44,5 +44,14 @@ def sales return sales end + def revenue + revenue = 0 + sales_array = self.sales + sales_array.each do |sale| + revenue = revenue + sale.amount + end + return revenue + end + end end diff --git a/spec/far_mar/vendor_spec.rb b/spec/far_mar/vendor_spec.rb index 28be5f9e..d1de9912 100644 --- a/spec/far_mar/vendor_spec.rb +++ b/spec/far_mar/vendor_spec.rb @@ -2,11 +2,12 @@ describe FarMar do describe FarMar::Vendor do + before :each do + vendor_info = CSV.open("./support/vendors.csv", 'r') { |csv| csv.first } + @vendor = FarMar::Vendor.new(vendor_info) + end + describe "#initialize" do - before :each do - vendor_info = CSV.open("./support/vendors.csv", 'r') { |csv| csv.first } - @vendor = FarMar::Vendor.new(vendor_info) - end it "creates a new instance of the Vendor class" do expect(@vendor).to be_an_instance_of(FarMar::Vendor) end @@ -46,10 +47,6 @@ end describe "#market" do - before :each do - vendor_info = CSV.open("./support/vendors.csv", 'r') { |csv| csv.first } - @vendor = FarMar::Vendor.new(vendor_info) - end it "returns an instance of the Market class" do expect(@vendor.market).to be_an_instance_of(FarMar::Market) end @@ -59,10 +56,6 @@ end describe "#products" do - before :each do - vendor_info = CSV.open("./support/vendors.csv", 'r') { |csv| csv.first } - @vendor = FarMar::Vendor.new(vendor_info) - end it "returns a collection" do expect(@vendor.products).to be_an(Array) end @@ -72,10 +65,6 @@ end describe "#sales" do - before :each do - vendor_info = CSV.open("./support/vendors.csv", 'r') { |csv| csv.first } - @vendor = FarMar::Vendor.new(vendor_info) - end it "returns a collection" do expect(@vendor.sales).to be_an(Array) end @@ -84,5 +73,14 @@ end end + describe "#revenue" do + it "returns a sum in cents" do + expect(@vendor.revenue).to be_a(Fixnum) + end + it "returns the sum of sales" do + expect(@vendor.revenue).to eq(38259) + end + end + end end From 594556cfb3623333e3fa06ae1d9973597ad6543d Mon Sep 17 00:00:00 2001 From: Jenna Nichols Date: Wed, 21 Oct 2015 14:01:53 -0700 Subject: [PATCH 15/47] self.by_market(market_id) method for Vendor class --- lib/far_mar/vendor.rb | 8 ++++++++ spec/far_mar/vendor_spec.rb | 11 +++++++++++ 2 files changed, 19 insertions(+) diff --git a/lib/far_mar/vendor.rb b/lib/far_mar/vendor.rb index 7dda7a1b..b3099c7a 100644 --- a/lib/far_mar/vendor.rb +++ b/lib/far_mar/vendor.rb @@ -53,5 +53,13 @@ def revenue return revenue end + def self.by_market(market_id) + local_vendors = FarMar::Vendor.all.find_all do |vendor| + vendor.id == market_id + end + return local_vendors + end + + end end diff --git a/spec/far_mar/vendor_spec.rb b/spec/far_mar/vendor_spec.rb index d1de9912..13eaa7ce 100644 --- a/spec/far_mar/vendor_spec.rb +++ b/spec/far_mar/vendor_spec.rb @@ -82,5 +82,16 @@ end end + describe ".by_market(market_id)" do + before :each do + @market_id = rand(1..500) + end + it "returns a collection" do + expect(FarMar::Vendor.by_market(@market_id)).to be_an(Array) + end + it "returns instances of Vendors" do + expect(FarMar::Vendor.by_market(@market_id)[0]).to be_an_instance_of(FarMar::Vendor) if FarMar::Vendor.by_market(@market_id).length > 0 + end + end end end From 08ad325a99d5eeb8570030e59b384a8ff6603b3d Mon Sep 17 00:00:00 2001 From: Jenna Nichols Date: Wed, 21 Oct 2015 14:11:08 -0700 Subject: [PATCH 16/47] vendor method for Product class --- lib/far_mar/product.rb | 5 +++++ spec/far_mar/product_spec.rb | 18 ++++++++++++++---- spec/far_mar/sale_spec.rb | 9 +++++---- 3 files changed, 24 insertions(+), 8 deletions(-) diff --git a/lib/far_mar/product.rb b/lib/far_mar/product.rb index 096d3a07..bdc51b2a 100644 --- a/lib/far_mar/product.rb +++ b/lib/far_mar/product.rb @@ -23,6 +23,11 @@ def self.find(id) end end + def vendor + FarMar::Vendor.all.find do |vendor| + vendor.id == self.vendor_id + end + end end end diff --git a/spec/far_mar/product_spec.rb b/spec/far_mar/product_spec.rb index b3ebc55c..bb5a7f61 100644 --- a/spec/far_mar/product_spec.rb +++ b/spec/far_mar/product_spec.rb @@ -1,12 +1,13 @@ require "spec_helper" describe FarMar do describe FarMar::Product do + + before :each do + product_info = CSV.open("./support/products.csv", 'r') { |csv| csv.first } + @product = FarMar::Product.new(product_info) + end describe "#initialize" do - before :each do - product_info = CSV.open("./support/products.csv", 'r') { |csv| csv.first } - @product = FarMar::Product.new(product_info) - end it "creates a new instance of the Product class" do expect(@product).to be_an_instance_of(FarMar::Product) end @@ -45,5 +46,14 @@ end end + describe "#vendor" do + it "returns an instance of the Vendor class" do + expect(@product.vendor).to be_an_instance_of(FarMar::Vendor) + end + it "returns the Vendor with the matching id" do + expect(@product.vendor_id).to eq(@product.vendor.id) + end + end + end end diff --git a/spec/far_mar/sale_spec.rb b/spec/far_mar/sale_spec.rb index b8956ee6..29a85ff4 100644 --- a/spec/far_mar/sale_spec.rb +++ b/spec/far_mar/sale_spec.rb @@ -1,12 +1,13 @@ require "spec_helper" describe FarMar do describe FarMar::Sale do + + before :each do + sale_info = CSV.open("./support/sales.csv", 'r') { |csv| csv.first } + @sale = FarMar::Sale.new(sale_info) + end describe "#initialize" do - before :each do - sale_info = CSV.open("./support/sales.csv", 'r') { |csv| csv.first } - @sale = FarMar::Sale.new(sale_info) - end it "creates a new instance of the Sale class" do expect(@sale).to be_an_instance_of(FarMar::Sale) end From 7f76ce55b64e053689a8448382bdf944f23be95c Mon Sep 17 00:00:00 2001 From: Jenna Nichols Date: Wed, 21 Oct 2015 14:13:16 -0700 Subject: [PATCH 17/47] sales method for Product class --- lib/far_mar/product.rb | 7 +++++++ spec/far_mar/product_spec.rb | 11 ++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/far_mar/product.rb b/lib/far_mar/product.rb index bdc51b2a..378dbcdd 100644 --- a/lib/far_mar/product.rb +++ b/lib/far_mar/product.rb @@ -29,5 +29,12 @@ def vendor end end + def sales + sales = FarMar::Sale.all.find_all do |sale| + sale.product_id == self.id + end + return sales + end + end end diff --git a/spec/far_mar/product_spec.rb b/spec/far_mar/product_spec.rb index bb5a7f61..f00700b8 100644 --- a/spec/far_mar/product_spec.rb +++ b/spec/far_mar/product_spec.rb @@ -1,7 +1,7 @@ require "spec_helper" describe FarMar do describe FarMar::Product do - + before :each do product_info = CSV.open("./support/products.csv", 'r') { |csv| csv.first } @product = FarMar::Product.new(product_info) @@ -55,5 +55,14 @@ end end + describe "#sales" do + it "returns a collection" do + expect(@product.sales).to be_an(Array) + end + it "returns instances of Sales" do + expect(@product.sales[0]).to be_an_instance_of(FarMar::Sale) if @product.sales.length > 0 + end + end + end end From 62c63967a444ce201fc315570ff47a2f6fdbbf16 Mon Sep 17 00:00:00 2001 From: Jenna Nichols Date: Wed, 21 Oct 2015 14:21:13 -0700 Subject: [PATCH 18/47] number_of_sales method in Product class --- lib/far_mar/product.rb | 4 ++++ spec/far_mar/product_spec.rb | 9 +++++++++ 2 files changed, 13 insertions(+) diff --git a/lib/far_mar/product.rb b/lib/far_mar/product.rb index 378dbcdd..9dec3d3f 100644 --- a/lib/far_mar/product.rb +++ b/lib/far_mar/product.rb @@ -36,5 +36,9 @@ def sales return sales end + def number_of_sales + return self.sales.length + end + end end diff --git a/spec/far_mar/product_spec.rb b/spec/far_mar/product_spec.rb index f00700b8..9309edd0 100644 --- a/spec/far_mar/product_spec.rb +++ b/spec/far_mar/product_spec.rb @@ -64,5 +64,14 @@ end end + describe "#number_of_sales" do + it "returns a number" do + expect(@product.number_of_sales).to be_a(Fixnum) + end + it "returns the correct number of sales" do + expect(@product.number_of_sales).to eq(7) + end + end + end end From 3ff488f0df2693cf8f182fdd4ad9b8a51fba6ee8 Mon Sep 17 00:00:00 2001 From: Jenna Nichols Date: Wed, 21 Oct 2015 14:29:03 -0700 Subject: [PATCH 19/47] self.by_vendor(vendor_id) method for Product class --- lib/far_mar/product.rb | 7 +++++++ lib/far_mar/vendor.rb | 4 ++-- spec/far_mar/product_spec.rb | 12 ++++++++++++ 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/lib/far_mar/product.rb b/lib/far_mar/product.rb index 9dec3d3f..60236d17 100644 --- a/lib/far_mar/product.rb +++ b/lib/far_mar/product.rb @@ -40,5 +40,12 @@ def number_of_sales return self.sales.length end + def self.by_vendor(vendor_id) + vendor_products = FarMar::Product.all.find_all do |product| + product.id == vendor_id + end + return vendor_products + end + end end diff --git a/lib/far_mar/vendor.rb b/lib/far_mar/vendor.rb index b3099c7a..0803c693 100644 --- a/lib/far_mar/vendor.rb +++ b/lib/far_mar/vendor.rb @@ -54,10 +54,10 @@ def revenue end def self.by_market(market_id) - local_vendors = FarMar::Vendor.all.find_all do |vendor| + market_vendors = FarMar::Vendor.all.find_all do |vendor| vendor.id == market_id end - return local_vendors + return market_vendors end diff --git a/spec/far_mar/product_spec.rb b/spec/far_mar/product_spec.rb index 9309edd0..f684b1d4 100644 --- a/spec/far_mar/product_spec.rb +++ b/spec/far_mar/product_spec.rb @@ -73,5 +73,17 @@ end end + describe ".by_vendor(vendor_id)" do + before :each do + @vendor_id = rand(1..2690) + end + it "returns a collection" do + expect(FarMar::Product.by_vendor(@vendor_id)).to be_an(Array) + end + it "returns instances of Products" do + expect(FarMar::Product.by_vendor(@vendor_id)[0]).to be_an_instance_of(FarMar::Product) if FarMar::Product.by_vendor(@vendor_id).length > 0 + end + end + end end From e4e0079462644ae43b7050662b1eb86958f73c46 Mon Sep 17 00:00:00 2001 From: Jenna Nichols Date: Wed, 21 Oct 2015 14:31:06 -0700 Subject: [PATCH 20/47] vendor method for Sale class --- lib/far_mar/sale.rb | 6 ++++++ spec/far_mar/sale_spec.rb | 11 ++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/far_mar/sale.rb b/lib/far_mar/sale.rb index 32cdd043..22ceec0d 100644 --- a/lib/far_mar/sale.rb +++ b/lib/far_mar/sale.rb @@ -25,5 +25,11 @@ def self.find(id) end end + def vendor + FarMar::Vendor.all.find do |vendor| + vendor.id == self.vendor_id + end + end + end end diff --git a/spec/far_mar/sale_spec.rb b/spec/far_mar/sale_spec.rb index 29a85ff4..cf4eb9d3 100644 --- a/spec/far_mar/sale_spec.rb +++ b/spec/far_mar/sale_spec.rb @@ -1,7 +1,7 @@ require "spec_helper" describe FarMar do describe FarMar::Sale do - + before :each do sale_info = CSV.open("./support/sales.csv", 'r') { |csv| csv.first } @sale = FarMar::Sale.new(sale_info) @@ -46,5 +46,14 @@ end end + describe "#vendor" do + it "returns an instance of the Vendor class" do + expect(@sale.vendor).to be_an_instance_of(FarMar::Vendor) + end + it "returns the Vendor with the matching id" do + expect(@sale.vendor_id).to eq(@sale.vendor.id) + end + end + end end From e6661c50b1dd441cc192a1761780d474115ef6a9 Mon Sep 17 00:00:00 2001 From: Jenna Nichols Date: Wed, 21 Oct 2015 14:33:10 -0700 Subject: [PATCH 21/47] product method for Sale class --- lib/far_mar/sale.rb | 6 ++++++ spec/far_mar/sale_spec.rb | 9 +++++++++ 2 files changed, 15 insertions(+) diff --git a/lib/far_mar/sale.rb b/lib/far_mar/sale.rb index 22ceec0d..2c4585f2 100644 --- a/lib/far_mar/sale.rb +++ b/lib/far_mar/sale.rb @@ -31,5 +31,11 @@ def vendor end end + def product + FarMar::Product.all.find do |product| + product.id == self.product_id + end + end + end end diff --git a/spec/far_mar/sale_spec.rb b/spec/far_mar/sale_spec.rb index cf4eb9d3..6a8554bd 100644 --- a/spec/far_mar/sale_spec.rb +++ b/spec/far_mar/sale_spec.rb @@ -55,5 +55,14 @@ end end + describe "#product" do + it "returns an instance of the Product class" do + expect(@sale.product).to be_an_instance_of(FarMar::Product) + end + it "returns the Product with the matching id" do + expect(@sale.product_id).to eq(@sale.product.id) + end + end + end end From a7a602ecbf5b947cc0fe9a9362af324a77916971 Mon Sep 17 00:00:00 2001 From: Jenna Nichols Date: Wed, 21 Oct 2015 15:14:27 -0700 Subject: [PATCH 22/47] time method for Sale class --- lib/far_mar/sale.rb | 9 ++++++++- spec/far_mar/sale_spec.rb | 16 ++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/lib/far_mar/sale.rb b/lib/far_mar/sale.rb index 2c4585f2..299c7e48 100644 --- a/lib/far_mar/sale.rb +++ b/lib/far_mar/sale.rb @@ -1,6 +1,6 @@ module FarMar class Sale - attr_reader :id, :vendor_id, :product_id, :amount + attr_reader :id, :vendor_id, :product_id, :amount, :purchase_time def initialize(sale_info) @id = sale_info[0].to_i @@ -37,5 +37,12 @@ def product end end + def self.between(beginning_time, end_time) + sales_between = FarMar::Sale.all.find_all do |sale| + sale.purchase_time.between?(beginning_time,end_time) + end + return sales_between + end + end end diff --git a/spec/far_mar/sale_spec.rb b/spec/far_mar/sale_spec.rb index 6a8554bd..5f0cbe82 100644 --- a/spec/far_mar/sale_spec.rb +++ b/spec/far_mar/sale_spec.rb @@ -64,5 +64,21 @@ end end + describe ".between(beginning_time, end_time)" do + before :each do + @beginning_time = DateTime.strptime("2013-11-06 08:35:40 -0800", "%Y-%m-%d %H:%M:%S %z") + @end_time = DateTime.strptime("2013-11-13 08:35:16 -0800", "%Y-%m-%d %H:%M:%S %z") + end + it "returns a collection" do + expect(FarMar::Sale.between(@beginning_time, @end_time)).to be_an(Array) + end + it "returns instances of the Sale class" do + expect(FarMar::Sale.between(@beginning_time, @end_time)[0]).to be_an_instance_of(FarMar::Sale) if FarMar::Sale.between(@beginning_time, @end_time).length > 0 + end + it "returns the correct number of Sale instances" do + expect(FarMar::Sale.between(@beginning_time, @end_time).length).to eq(12798) + end + end + end end From bc01376e46a7e3d8390edcf3d97256c163757d41 Mon Sep 17 00:00:00 2001 From: Jenna Nichols Date: Wed, 21 Oct 2015 15:31:55 -0700 Subject: [PATCH 23/47] additional test for time method in Sale class --- spec/far_mar/sale_spec.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/spec/far_mar/sale_spec.rb b/spec/far_mar/sale_spec.rb index 5f0cbe82..1126f8cb 100644 --- a/spec/far_mar/sale_spec.rb +++ b/spec/far_mar/sale_spec.rb @@ -68,6 +68,8 @@ before :each do @beginning_time = DateTime.strptime("2013-11-06 08:35:40 -0800", "%Y-%m-%d %H:%M:%S %z") @end_time = DateTime.strptime("2013-11-13 08:35:16 -0800", "%Y-%m-%d %H:%M:%S %z") + @begin2 = DateTime.strptime("2013-11-06 08:35:40 -0800", "%Y-%m-%d %H:%M:%S %z") + @end2 = DateTime.strptime("2013-11-06 08:42:09 -0800", "%Y-%m-%d %H:%M:%S %z") end it "returns a collection" do expect(FarMar::Sale.between(@beginning_time, @end_time)).to be_an(Array) @@ -77,6 +79,7 @@ end it "returns the correct number of Sale instances" do expect(FarMar::Sale.between(@beginning_time, @end_time).length).to eq(12798) + expect(FarMar::Sale.between(@begin2, @end2).length).to eq(10) end end From bb0d7909f4b7ac963cacda6d490c915e86c85be1 Mon Sep 17 00:00:00 2001 From: Jenna Nichols Date: Wed, 21 Oct 2015 15:50:19 -0700 Subject: [PATCH 24/47] refactored market specs --- spec/far_mar/market_spec.rb | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/spec/far_mar/market_spec.rb b/spec/far_mar/market_spec.rb index 77ec27a5..4a69bc13 100644 --- a/spec/far_mar/market_spec.rb +++ b/spec/far_mar/market_spec.rb @@ -2,11 +2,12 @@ describe FarMar do describe FarMar::Market do + before :each do + market_info = ["1","People's Co-op Farmers Market","30th and Burnside","Portland","Multnomah","Oregon","97202"] + @market = FarMar::Market.new(market_info) + end + describe "#initialize" do - before :each do - market_info = CSV.open("./support/markets.csv", 'r') { |csv| csv.first } - @market = FarMar::Market.new(market_info) - end it "creates a new instance of the Market class" do expect(@market).to be_an_instance_of(FarMar::Market) end @@ -45,10 +46,6 @@ end describe "#vendors" do - before :each do - market_info = CSV.open("./support/markets.csv", 'r') { |csv| csv.first } - @market = FarMar::Market.new(market_info) - end it "returns a collection" do expect(@market.vendors).to be_an(Array) end From 50cfe814dd4864256918201a1e92df2e471d054c Mon Sep 17 00:00:00 2001 From: Jenna Nichols Date: Wed, 21 Oct 2015 16:05:09 -0700 Subject: [PATCH 25/47] updated self.all methods to be faster --- lib/far_mar/market.rb | 15 ++++++++++----- lib/far_mar/product.rb | 14 +++++++++----- lib/far_mar/sale.rb | 14 +++++++++----- lib/far_mar/vendor.rb | 14 +++++++++----- 4 files changed, 37 insertions(+), 20 deletions(-) diff --git a/lib/far_mar/market.rb b/lib/far_mar/market.rb index 55dff745..6dc17bd2 100644 --- a/lib/far_mar/market.rb +++ b/lib/far_mar/market.rb @@ -14,14 +14,19 @@ def initialize(market_info) def self.all - market_array = [] - CSV.read("./support/markets.csv").each do |market| - new_market = FarMar::Market.new(market) - market_array.push(new_market) + @@market_array ||= [] + + if @@market_array == [] + CSV.read("./support/markets.csv").each do |market| + new_market = FarMar::Market.new(market) + @@market_array.push(new_market) + end end - return market_array + + return @@market_array end + def self.find(id) FarMar::Market.all.find do |market| market.id == id diff --git a/lib/far_mar/product.rb b/lib/far_mar/product.rb index 60236d17..3a94f4a5 100644 --- a/lib/far_mar/product.rb +++ b/lib/far_mar/product.rb @@ -9,12 +9,16 @@ def initialize(product_info) end def self.all - product_array = [] - CSV.read("./support/products.csv").each do |product| - new_product = FarMar::Product.new(product) - product_array.push(new_product) + @@product_array ||= [] + + if @@product_array == [] + CSV.read("./support/products.csv").each do |product| + new_product = FarMar::Product.new(product) + @@product_array.push(new_product) + end end - return product_array + + return @@product_array end def self.find(id) diff --git a/lib/far_mar/sale.rb b/lib/far_mar/sale.rb index 299c7e48..bfe11e76 100644 --- a/lib/far_mar/sale.rb +++ b/lib/far_mar/sale.rb @@ -11,12 +11,16 @@ def initialize(sale_info) end def self.all - sale_array = [] - CSV.read("./support/sales.csv").each do |sale| - new_sale = FarMar::Sale.new(sale) - sale_array.push(new_sale) + @@sale_array ||= [] + + if @@sale_array == [] + CSV.read("./support/sales.csv").each do |sale| + new_sale = FarMar::Sale.new(sale) + @@sale_array.push(new_sale) + end end - return sale_array + + return @@sale_array end def self.find(id) diff --git a/lib/far_mar/vendor.rb b/lib/far_mar/vendor.rb index 0803c693..49726fb0 100644 --- a/lib/far_mar/vendor.rb +++ b/lib/far_mar/vendor.rb @@ -10,12 +10,16 @@ def initialize(vendor_info) end def self.all - vendor_array = [] - CSV.read("./support/vendors.csv").each do |vendor| - new_vendor = FarMar::Vendor.new(vendor) - vendor_array.push(new_vendor) + @@vendor_array ||= [] + + if @@vendor_array == [] + CSV.read("./support/vendors.csv").each do |vendor| + new_vendor = FarMar::Vendor.new(vendor) + @@vendor_array.push(new_vendor) + end end - return vendor_array + + return @@vendor_array end def self.find(id) From cff392ecd1e511e49cba801deb0abc862659d414 Mon Sep 17 00:00:00 2001 From: Jenna Nichols Date: Wed, 21 Oct 2015 16:14:59 -0700 Subject: [PATCH 26/47] refactored specs for creating example instances --- spec/far_mar/product_spec.rb | 2 +- spec/far_mar/sale_spec.rb | 2 +- spec/far_mar/vendor_spec.rb | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/far_mar/product_spec.rb b/spec/far_mar/product_spec.rb index f684b1d4..7565bf3f 100644 --- a/spec/far_mar/product_spec.rb +++ b/spec/far_mar/product_spec.rb @@ -3,7 +3,7 @@ describe FarMar::Product do before :each do - product_info = CSV.open("./support/products.csv", 'r') { |csv| csv.first } + product_info = ["1","Dry Beets","1"] @product = FarMar::Product.new(product_info) end diff --git a/spec/far_mar/sale_spec.rb b/spec/far_mar/sale_spec.rb index 1126f8cb..f678cc1e 100644 --- a/spec/far_mar/sale_spec.rb +++ b/spec/far_mar/sale_spec.rb @@ -3,7 +3,7 @@ describe FarMar::Sale do before :each do - sale_info = CSV.open("./support/sales.csv", 'r') { |csv| csv.first } + sale_info = ["1","9290","2013-11-07 04:34:56 -0800","1","1"] @sale = FarMar::Sale.new(sale_info) end diff --git a/spec/far_mar/vendor_spec.rb b/spec/far_mar/vendor_spec.rb index 13eaa7ce..9f1f672f 100644 --- a/spec/far_mar/vendor_spec.rb +++ b/spec/far_mar/vendor_spec.rb @@ -3,7 +3,7 @@ describe FarMar::Vendor do before :each do - vendor_info = CSV.open("./support/vendors.csv", 'r') { |csv| csv.first } + vendor_info = ["1","Feil-Farrell","8","1"] @vendor = FarMar::Vendor.new(vendor_info) end From 328b7756095a60b0408f067426d7097031715886 Mon Sep 17 00:00:00 2001 From: Jenna Nichols Date: Wed, 21 Oct 2015 16:25:13 -0700 Subject: [PATCH 27/47] additional tests in Vendor class --- spec/far_mar/vendor_spec.rb | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/spec/far_mar/vendor_spec.rb b/spec/far_mar/vendor_spec.rb index 9f1f672f..5d8d5bd0 100644 --- a/spec/far_mar/vendor_spec.rb +++ b/spec/far_mar/vendor_spec.rb @@ -3,8 +3,12 @@ describe FarMar::Vendor do before :each do - vendor_info = ["1","Feil-Farrell","8","1"] - @vendor = FarMar::Vendor.new(vendor_info) + vendor1_info = ["1","Feil-Farrell","8","1"] + @vendor = FarMar::Vendor.new(vendor1_info) + vendor2_info = ["2","Hamill, Kilback and Pfeffer","5","1"] + @vendor2 = FarMar::Vendor.new(vendor2_info) + vendor51_info = ["51","Bernier Inc","1","12"] + @vendor51 = FarMar::Vendor.new(vendor51_info) end describe "#initialize" do @@ -13,6 +17,7 @@ end it "retrieves the vendor ID from the vendor info array" do expect(@vendor.id).to eq(1) + expect(@vendor51.id).to eq(51) end end @@ -67,6 +72,7 @@ describe "#sales" do it "returns a collection" do expect(@vendor.sales).to be_an(Array) + expect(@vendor51.sales).to be_an(Array) end it "returns instances of Sales" do expect(@vendor.sales[0]).to be_an_instance_of(FarMar::Sale) if @vendor.sales.length > 0 @@ -79,6 +85,8 @@ end it "returns the sum of sales" do expect(@vendor.revenue).to eq(38259) + expect(@vendor2.revenue).to eq(5727) + expect(@vendor51.revenue).to eq(0) end end From 66343bba457ed8a0be81598c989121892971decd Mon Sep 17 00:00:00 2001 From: Jenna Nichols Date: Wed, 21 Oct 2015 16:31:36 -0700 Subject: [PATCH 28/47] added additional case for Product tests --- spec/far_mar/product_spec.rb | 3 +++ spec/far_mar/vendor_spec.rb | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/spec/far_mar/product_spec.rb b/spec/far_mar/product_spec.rb index 7565bf3f..8001d729 100644 --- a/spec/far_mar/product_spec.rb +++ b/spec/far_mar/product_spec.rb @@ -5,6 +5,8 @@ before :each do product_info = ["1","Dry Beets","1"] @product = FarMar::Product.new(product_info) + product3_info = ["3","Heavy Chicken","2"] + @product3 = FarMar::Product.new(product3_info) end describe "#initialize" do @@ -70,6 +72,7 @@ end it "returns the correct number of sales" do expect(@product.number_of_sales).to eq(7) + expect(@product3.number_of_sales).to eq(0) end end diff --git a/spec/far_mar/vendor_spec.rb b/spec/far_mar/vendor_spec.rb index 5d8d5bd0..9a7153c7 100644 --- a/spec/far_mar/vendor_spec.rb +++ b/spec/far_mar/vendor_spec.rb @@ -3,8 +3,8 @@ describe FarMar::Vendor do before :each do - vendor1_info = ["1","Feil-Farrell","8","1"] - @vendor = FarMar::Vendor.new(vendor1_info) + vendor_info = ["1","Feil-Farrell","8","1"] + @vendor = FarMar::Vendor.new(vendor_info) vendor2_info = ["2","Hamill, Kilback and Pfeffer","5","1"] @vendor2 = FarMar::Vendor.new(vendor2_info) vendor51_info = ["51","Bernier Inc","1","12"] From 7073a69862cdbbe4455ad06c7c8a9d303836baec Mon Sep 17 00:00:00 2001 From: Jenna Nichols Date: Wed, 21 Oct 2015 16:36:46 -0700 Subject: [PATCH 29/47] done with primary reqs and basic refactoring --- lib/far_mar/market.rb | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/far_mar/market.rb b/lib/far_mar/market.rb index 6dc17bd2..1e01edcd 100644 --- a/lib/far_mar/market.rb +++ b/lib/far_mar/market.rb @@ -12,7 +12,6 @@ def initialize(market_info) @zip = market_info[6] end - def self.all @@market_array ||= [] @@ -22,11 +21,10 @@ def self.all @@market_array.push(new_market) end end - + return @@market_array end - def self.find(id) FarMar::Market.all.find do |market| market.id == id From d87afd2d4b055c0d4ebd5c4550a2ea9b6ad7225d Mon Sep 17 00:00:00 2001 From: Jenna Nichols Date: Wed, 21 Oct 2015 17:01:18 -0700 Subject: [PATCH 30/47] added possible formatting to time method in Sale class --- lib/far_mar/sale.rb | 8 +++++++- spec/far_mar/sale_spec.rb | 3 +++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/far_mar/sale.rb b/lib/far_mar/sale.rb index bfe11e76..cdc81c75 100644 --- a/lib/far_mar/sale.rb +++ b/lib/far_mar/sale.rb @@ -19,7 +19,7 @@ def self.all @@sale_array.push(new_sale) end end - + return @@sale_array end @@ -42,6 +42,12 @@ def product end def self.between(beginning_time, end_time) + if beginning_time.class == String + beginning_time = DateTime.strptime(beginning_time, "%Y-%m-%d %H:%M:%S %z") + end + if end_time.class == String + end_time = DateTime.strptime(end_time, "%Y-%m-%d %H:%M:%S %z") + end sales_between = FarMar::Sale.all.find_all do |sale| sale.purchase_time.between?(beginning_time,end_time) end diff --git a/spec/far_mar/sale_spec.rb b/spec/far_mar/sale_spec.rb index f678cc1e..848627e0 100644 --- a/spec/far_mar/sale_spec.rb +++ b/spec/far_mar/sale_spec.rb @@ -70,6 +70,8 @@ @end_time = DateTime.strptime("2013-11-13 08:35:16 -0800", "%Y-%m-%d %H:%M:%S %z") @begin2 = DateTime.strptime("2013-11-06 08:35:40 -0800", "%Y-%m-%d %H:%M:%S %z") @end2 = DateTime.strptime("2013-11-06 08:42:09 -0800", "%Y-%m-%d %H:%M:%S %z") + @begin_string = "2013-11-06 08:35:40 -0800" + @end_string = "2013-11-13 08:35:16 -0800" end it "returns a collection" do expect(FarMar::Sale.between(@beginning_time, @end_time)).to be_an(Array) @@ -79,6 +81,7 @@ end it "returns the correct number of Sale instances" do expect(FarMar::Sale.between(@beginning_time, @end_time).length).to eq(12798) + expect(FarMar::Sale.between(@begin_string, @end_string).length).to eq(12798) expect(FarMar::Sale.between(@begin2, @end2).length).to eq(10) end end From 34c851bface558c6259b98c2ba62ee4d43e075f8 Mon Sep 17 00:00:00 2001 From: Jenna Nichols Date: Wed, 21 Oct 2015 18:35:29 -0700 Subject: [PATCH 31/47] first pass at product method in Market class --- lib/far_mar/market.rb | 12 ++++++++++++ spec/far_mar/market_spec.rb | 9 +++++++++ 2 files changed, 21 insertions(+) diff --git a/lib/far_mar/market.rb b/lib/far_mar/market.rb index 1e01edcd..ae448505 100644 --- a/lib/far_mar/market.rb +++ b/lib/far_mar/market.rb @@ -38,5 +38,17 @@ def vendors return vendors end + def products + products = [] + vendors = self.vendors + vendors.each do |vendor| + vendor_products = vendor.products + vendor_products.each do |vendor_product| + products.push(vendor_product) + end + end + return products + end + end end diff --git a/spec/far_mar/market_spec.rb b/spec/far_mar/market_spec.rb index 4a69bc13..733f29fa 100644 --- a/spec/far_mar/market_spec.rb +++ b/spec/far_mar/market_spec.rb @@ -53,6 +53,15 @@ expect(@market.vendors[0]).to be_an_instance_of(FarMar::Vendor) if @market.vendors.length > 0 end end + + describe "#products" do + it "returns a collection" do + expect(@market.products).to be_an(Array) + end + it "returns instances of Products" do + expect(@market.products[0]).to be_an_instance_of(FarMar::Product) if @market.products.length > 0 + end + end end end From 091ad572c5b5ee6223f7c8feebf3ace0a3889d74 Mon Sep 17 00:00:00 2001 From: Jenna Nichols Date: Wed, 21 Oct 2015 18:41:12 -0700 Subject: [PATCH 32/47] added test to products method in Market class --- spec/far_mar/market_spec.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/spec/far_mar/market_spec.rb b/spec/far_mar/market_spec.rb index 733f29fa..f810ea83 100644 --- a/spec/far_mar/market_spec.rb +++ b/spec/far_mar/market_spec.rb @@ -61,6 +61,9 @@ it "returns instances of Products" do expect(@market.products[0]).to be_an_instance_of(FarMar::Product) if @market.products.length > 0 end + it "contains Products from Vendors at that Market" do + expect(@market.products[0].vendor_id).to eq(@market.id) + end end end From e3fbd758f1c661fe4cf61487defbbdc0545569cc Mon Sep 17 00:00:00 2001 From: Jenna Nichols Date: Wed, 21 Oct 2015 19:01:10 -0700 Subject: [PATCH 33/47] first pass at search method in Market class --- lib/far_mar/market.rb | 15 ++++++++++++++- lib/far_mar/vendor.rb | 2 +- spec/far_mar/market_spec.rb | 11 ++++++++++- 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/lib/far_mar/market.rb b/lib/far_mar/market.rb index ae448505..2d9a2784 100644 --- a/lib/far_mar/market.rb +++ b/lib/far_mar/market.rb @@ -1,6 +1,6 @@ module FarMar class Market - attr_reader :id + attr_reader :id, :name def initialize(market_info) @id = market_info[0].to_i @@ -50,5 +50,18 @@ def products return products end + def self.search(search_term) + results = [] + name_matches = FarMar::Market.all.find_all do |market| + market.name.downcase.include?(search_term.downcase) + end + name_matches.each { |match| results.push(match)} + vendor_matches = FarMar::Vendor.all.find_all do |vendor| + vendor.name.downcase.include?(search_term.downcase) + end + vendor_matches.each { |match| results.push(match)} + return results + end + end end diff --git a/lib/far_mar/vendor.rb b/lib/far_mar/vendor.rb index 49726fb0..ccb6d965 100644 --- a/lib/far_mar/vendor.rb +++ b/lib/far_mar/vendor.rb @@ -1,6 +1,6 @@ module FarMar class Vendor - attr_reader :id, :market_id + attr_reader :id, :market_id, :name def initialize(vendor_info) @id = vendor_info[0].to_i diff --git a/spec/far_mar/market_spec.rb b/spec/far_mar/market_spec.rb index f810ea83..f0e93089 100644 --- a/spec/far_mar/market_spec.rb +++ b/spec/far_mar/market_spec.rb @@ -62,7 +62,16 @@ expect(@market.products[0]).to be_an_instance_of(FarMar::Product) if @market.products.length > 0 end it "contains Products from Vendors at that Market" do - expect(@market.products[0].vendor_id).to eq(@market.id) + expect(@market.products[0].vendor_id).to eq(@market.id) if @market.products.length > 0 + end + end + + describe ".search(search_term)" do + before :each do + @search_term = "school" + end + it "returns a collection" do + expect(FarMar::Market.search(@search_term)).to be_an(Array) end end end From ed2a177b70216767d59b3bc7cd4a1d6b83f57697 Mon Sep 17 00:00:00 2001 From: Jenna Nichols Date: Wed, 21 Oct 2015 19:07:14 -0700 Subject: [PATCH 34/47] added test to search method in Market class --- spec/far_mar/market_spec.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/spec/far_mar/market_spec.rb b/spec/far_mar/market_spec.rb index f0e93089..0265a260 100644 --- a/spec/far_mar/market_spec.rb +++ b/spec/far_mar/market_spec.rb @@ -73,6 +73,9 @@ it "returns a collection" do expect(FarMar::Market.search(@search_term)).to be_an(Array) end + it "returns the correct number of matches" do + expect(FarMar::Market.search("school").length).to eq(3) + end end end From a398fd797a2c30e36a4d66b86fd896bfda2d25a4 Mon Sep 17 00:00:00 2001 From: Jenna Nichols Date: Wed, 21 Oct 2015 19:09:41 -0700 Subject: [PATCH 35/47] fixed variable labels --- spec/far_mar/product_spec.rb | 6 +++--- spec/far_mar/sale_spec.rb | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/spec/far_mar/product_spec.rb b/spec/far_mar/product_spec.rb index 8001d729..5ae6dc40 100644 --- a/spec/far_mar/product_spec.rb +++ b/spec/far_mar/product_spec.rb @@ -29,10 +29,10 @@ expect(FarMar::Product.all.length).to eq(@products.size) end it "contains instances of the Product class" do - vendor_total = FarMar::Product.all.length + product_total = FarMar::Product.all.length expect(FarMar::Product.all[0]).to be_an_instance_of(FarMar::Product) - expect(FarMar::Product.all[vendor_total - 1]).to be_an_instance_of(FarMar::Product) - expect(FarMar::Product.all[vendor_total]).to be nil + expect(FarMar::Product.all[product_total - 1]).to be_an_instance_of(FarMar::Product) + expect(FarMar::Product.all[product_total]).to be nil end end diff --git a/spec/far_mar/sale_spec.rb b/spec/far_mar/sale_spec.rb index 848627e0..d2148dc8 100644 --- a/spec/far_mar/sale_spec.rb +++ b/spec/far_mar/sale_spec.rb @@ -27,10 +27,10 @@ expect(FarMar::Sale.all.length).to eq(@sales.size) end it "contains instances of the Sale class" do - vendor_total = FarMar::Sale.all.length + sale_total = FarMar::Sale.all.length expect(FarMar::Sale.all[0]).to be_an_instance_of(FarMar::Sale) - expect(FarMar::Sale.all[vendor_total - 1]).to be_an_instance_of(FarMar::Sale) - expect(FarMar::Sale.all[vendor_total]).to be nil + expect(FarMar::Sale.all[sale_total - 1]).to be_an_instance_of(FarMar::Sale) + expect(FarMar::Sale.all[sale_total]).to be nil end end From c4571ab95c32356046e66e973288a6dc876480fa Mon Sep 17 00:00:00 2001 From: Jenna Nichols Date: Wed, 21 Oct 2015 19:25:05 -0700 Subject: [PATCH 36/47] best and worst vendor methods in Market class --- lib/far_mar/market.rb | 16 ++++++++++++++++ spec/far_mar/market_spec.rb | 22 +++++++++++++++++++++- 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/lib/far_mar/market.rb b/lib/far_mar/market.rb index 2d9a2784..c1bfb1e8 100644 --- a/lib/far_mar/market.rb +++ b/lib/far_mar/market.rb @@ -63,5 +63,21 @@ def self.search(search_term) return results end + def preferred_vendor + vendors = self.vendors + best_vendor = vendors.max_by do |vendor| + vendor.revenue + end + return best_vendor + end + + def worst_vendor + vendors = self.vendors + worst_vendor = vendors.min_by do |vendor| + vendor.revenue + end + return worst_vendor + end + end end diff --git a/spec/far_mar/market_spec.rb b/spec/far_mar/market_spec.rb index 0265a260..b1b00a10 100644 --- a/spec/far_mar/market_spec.rb +++ b/spec/far_mar/market_spec.rb @@ -77,7 +77,27 @@ expect(FarMar::Market.search("school").length).to eq(3) end end - end + describe "#preferred_vendor" do + it "returns an instance of Vendor" do + expect(@market.preferred_vendor).to be_an_instance_of(FarMar::Vendor) + end + it "returns the Vendor with the most revenue" do + expect(@market.preferred_vendor.id).to eq(5) + end + end + + describe "#worst_vendor" do + it "returns an instance of Vendor" do + expect(@market.worst_vendor).to be_an_instance_of(FarMar::Vendor) + end + it "returns the Vendor with the most revenue" do + expect(@market.worst_vendor.id).to eq(6) + end + end + + + + end end end From e0a6fbdc8d987591ca7475a8dbcba95fa06703a0 Mon Sep 17 00:00:00 2001 From: Jenna Nichols Date: Wed, 21 Oct 2015 19:30:23 -0700 Subject: [PATCH 37/47] skeleton for best vendor by date --- lib/far_mar/market.rb | 4 ++++ spec/far_mar/market_spec.rb | 9 +++++++++ 2 files changed, 13 insertions(+) diff --git a/lib/far_mar/market.rb b/lib/far_mar/market.rb index c1bfb1e8..2079660b 100644 --- a/lib/far_mar/market.rb +++ b/lib/far_mar/market.rb @@ -71,6 +71,10 @@ def preferred_vendor return best_vendor end + def preferred_vendor(date) + + end + def worst_vendor vendors = self.vendors worst_vendor = vendors.min_by do |vendor| diff --git a/spec/far_mar/market_spec.rb b/spec/far_mar/market_spec.rb index b1b00a10..caf4d880 100644 --- a/spec/far_mar/market_spec.rb +++ b/spec/far_mar/market_spec.rb @@ -87,6 +87,15 @@ end end + describe "#preferred_vendor(date)" do + before :each do + @date = # some date, how to format?? + end + it "returns an instance of Vendor" do + expect(@market.preferred_vendor(@date)).to be_an_instance_of(FarMar::Vendor) + end + end + describe "#worst_vendor" do it "returns an instance of Vendor" do expect(@market.worst_vendor).to be_an_instance_of(FarMar::Vendor) From fcccc00d4b181a8834f415fd1e7d9b157ab133f7 Mon Sep 17 00:00:00 2001 From: Jenna Nichols Date: Thu, 22 Oct 2015 11:52:43 -0700 Subject: [PATCH 38/47] best vendor by date --- lib/far_mar/market.rb | 19 ++++++++++++++++++- spec/far_mar/market_spec.rb | 11 ++++++++--- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/lib/far_mar/market.rb b/lib/far_mar/market.rb index 2079660b..8def1165 100644 --- a/lib/far_mar/market.rb +++ b/lib/far_mar/market.rb @@ -71,8 +71,25 @@ def preferred_vendor return best_vendor end - def preferred_vendor(date) + def preferred_vendor_by_date(date) + # expecting a string in the form yyyy-mm-dd + date = Date.parse(date.to_s) + vendors = self.vendors + vendor_hash = {} + vendors.each do |vendor| + vendor_sales = vendor.sales + day_sales = vendor_sales.find_all do |sale| + date == sale.purchase_time.to_date + end + day_revenue = 0 + day_sales.each do |sale| + day_revenue = day_revenue + sale.amount + end + vendor_hash[vendor.id] = day_revenue + end + best_vendor_id = vendor_hash.key(vendor_hash.values.max) + return FarMar::Vendor.find(best_vendor_id) end def worst_vendor diff --git a/spec/far_mar/market_spec.rb b/spec/far_mar/market_spec.rb index caf4d880..5eae4b1f 100644 --- a/spec/far_mar/market_spec.rb +++ b/spec/far_mar/market_spec.rb @@ -5,6 +5,8 @@ before :each do market_info = ["1","People's Co-op Farmers Market","30th and Burnside","Portland","Multnomah","Oregon","97202"] @market = FarMar::Market.new(market_info) + market2_info = ["2","Silverdale Farmers Market","98383","Silverdale","Kitsap","Washington","98383"] + @market2 = FarMar::Market.new(market2_info) end describe "#initialize" do @@ -87,12 +89,15 @@ end end - describe "#preferred_vendor(date)" do + describe "#preferred_vendor_by_date(date)" do before :each do - @date = # some date, how to format?? + @date = DateTime.strptime("2013-11-07", "%Y-%m-%d") end it "returns an instance of Vendor" do - expect(@market.preferred_vendor(@date)).to be_an_instance_of(FarMar::Vendor) + expect(@market.preferred_vendor_by_date(@date)).to be_an_instance_of(FarMar::Vendor) + end + it "returns the Vendor with the best sales that day" do + expect(@market2.preferred_vendor_by_date(@date).id).to eq(7) end end From 5fdc4f8058b47e6942566b38fb4f53118ad7bd16 Mon Sep 17 00:00:00 2001 From: Jenna Nichols Date: Thu, 22 Oct 2015 11:56:24 -0700 Subject: [PATCH 39/47] worst vendor by date --- lib/far_mar/market.rb | 21 +++++++++++++++++++++ spec/far_mar/market_spec.rb | 14 +++++++++++++- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/lib/far_mar/market.rb b/lib/far_mar/market.rb index 8def1165..d798ab89 100644 --- a/lib/far_mar/market.rb +++ b/lib/far_mar/market.rb @@ -100,5 +100,26 @@ def worst_vendor return worst_vendor end + def worst_vendor_by_date(date) + # expecting a string in the form yyyy-mm-dd + date = Date.parse(date.to_s) + + vendors = self.vendors + vendor_hash = {} + vendors.each do |vendor| + vendor_sales = vendor.sales + day_sales = vendor_sales.find_all do |sale| + date == sale.purchase_time.to_date + end + day_revenue = 0 + day_sales.each do |sale| + day_revenue = day_revenue + sale.amount + end + vendor_hash[vendor.id] = day_revenue + end + worst_vendor_id = vendor_hash.key(vendor_hash.values.min) + return FarMar::Vendor.find(worst_vendor_id) + end + end end diff --git a/spec/far_mar/market_spec.rb b/spec/far_mar/market_spec.rb index 5eae4b1f..7e5525ec 100644 --- a/spec/far_mar/market_spec.rb +++ b/spec/far_mar/market_spec.rb @@ -97,7 +97,7 @@ expect(@market.preferred_vendor_by_date(@date)).to be_an_instance_of(FarMar::Vendor) end it "returns the Vendor with the best sales that day" do - expect(@market2.preferred_vendor_by_date(@date).id).to eq(7) + expect(@market2.preferred_vendor_by_date(@date).id).to eq(7) end end @@ -110,6 +110,18 @@ end end + describe "#worst_vendor_by_date(date)" do + before :each do + @date = DateTime.strptime("2013-11-07", "%Y-%m-%d") + end + it "returns an instance of Vendor" do + expect(@market.worst_vendor_by_date(@date)).to be_an_instance_of(FarMar::Vendor) + end + it "returns the Vendor with the worst sales that day" do + expect(@market2.worst_vendor_by_date(@date).id).to eq(9) + end + end + end From 37710ed21407139088656186d26084ecf5ba5e71 Mon Sep 17 00:00:00 2001 From: Jenna Nichols Date: Thu, 22 Oct 2015 14:13:23 -0700 Subject: [PATCH 40/47] more methods --- lib/far_mar/vendor.rb | 26 +++++++++++++++++++++++ spec/far_mar/market_spec.rb | 4 ++-- spec/far_mar/vendor_spec.rb | 42 +++++++++++++++++++++++++++++++++++++ support/sample_markets.csv | 9 ++++++++ 4 files changed, 79 insertions(+), 2 deletions(-) create mode 100644 support/sample_markets.csv diff --git a/lib/far_mar/vendor.rb b/lib/far_mar/vendor.rb index ccb6d965..e6e692b9 100644 --- a/lib/far_mar/vendor.rb +++ b/lib/far_mar/vendor.rb @@ -64,6 +64,32 @@ def self.by_market(market_id) return market_vendors end + def self.most_revenue(n) + sorted_vendors = FarMar::Vendor.all.sort_by do |vendor| + vendor.revenue + end + sorted_vendors.reverse! + return sorted_vendors[0..n-1] + end + + def self.most_items(n) + sorted_vendors = FarMar::Vendor.all.sort_by do |vendor| + vendor.products.length + end + sorted_vendors.reverse! + return sorted_vendors[0..n-1] + end + + def self.revenue_by_date(date) + date = Date.parse(date.to_s) + total_revenue = 0 + day_sales = FarMar::Sale.all.each do |sale| + if sale.purchase_time.to_date == date + total_revenue = total_revenue + sale.amount + end + end + return total_revenue + end end end diff --git a/spec/far_mar/market_spec.rb b/spec/far_mar/market_spec.rb index 7e5525ec..7de47ab7 100644 --- a/spec/far_mar/market_spec.rb +++ b/spec/far_mar/market_spec.rb @@ -91,7 +91,7 @@ describe "#preferred_vendor_by_date(date)" do before :each do - @date = DateTime.strptime("2013-11-07", "%Y-%m-%d") + @date = "2013-11-07" end it "returns an instance of Vendor" do expect(@market.preferred_vendor_by_date(@date)).to be_an_instance_of(FarMar::Vendor) @@ -112,7 +112,7 @@ describe "#worst_vendor_by_date(date)" do before :each do - @date = DateTime.strptime("2013-11-07", "%Y-%m-%d") + @date = "2013-11-07" end it "returns an instance of Vendor" do expect(@market.worst_vendor_by_date(@date)).to be_an_instance_of(FarMar::Vendor) diff --git a/spec/far_mar/vendor_spec.rb b/spec/far_mar/vendor_spec.rb index 9a7153c7..62c10e19 100644 --- a/spec/far_mar/vendor_spec.rb +++ b/spec/far_mar/vendor_spec.rb @@ -101,5 +101,47 @@ expect(FarMar::Vendor.by_market(@market_id)[0]).to be_an_instance_of(FarMar::Vendor) if FarMar::Vendor.by_market(@market_id).length > 0 end end + + # describe ".most_revenue(n)" do + # before :each do + # @n = 2 + # end + # it "returns a collection" do + # expect(FarMar::Vendor.most_revenue(@n)).to be_an(Array) + # end + # it "returns a list of Vendors" do + # expect(FarMar::Vendor.most_revenue(2)[0]).to be_an_instance_of(FarMar::Vendor) + # expect(FarMar::Vendor.most_revenue(2)[1]).to be_an_instance_of(FarMar::Vendor) + # end + # it "returns an ranked list, sorted highest to lowest" do + # expect(FarMar::Vendor.most_revenue(2)[0].revenue).to be > FarMar::Vendor.most_revenue(2)[1].revenue if FarMar::Vendor.most_revenue(2).length > 1 + # end + # end + # + # describe ".most_items(n)" do + # before :each do + # @n = 2 + # end + # it "returns a collection" do + # expect(FarMar::Vendor.most_items(@n)).to be_an(Array) + # end + # it "returns a list of Vendors" do + # expect(FarMar::Vendor.most_items(@n)[0]).to be_an_instance_of(FarMar::Vendor) + # expect(FarMar::Vendor.most_items(@n)[1]).to be_an_instance_of(FarMar::Vendor) + # end + # it "returns a ranked list, sorted highest to lowest" do + # expect(FarMar::Vendor.most_items(2)[0].products.length).to be >= FarMar::Vendor.most_items(2)[1].products.length if FarMar::Vendor.most_items(2).length > 1 + # end + # end + + describe ".revenue_by_date(date)" do + before :each do + @date = "2013-11-07" + end + it "returns a number" do + expect(FarMar::Vendor.revenue_by_date(@date)).to be_a(Fixnum) + end + end + end end diff --git a/support/sample_markets.csv b/support/sample_markets.csv new file mode 100644 index 00000000..1ddb3585 --- /dev/null +++ b/support/sample_markets.csv @@ -0,0 +1,9 @@ +1,People's Co-op Farmers Market,30th and Burnside,Portland,Multnomah,Oregon,97202 +2,Silverdale Farmers Market,98383,Silverdale,Kitsap,Washington,98383 +3,Dolgeville Farmer's Market,(Parking Lot) Between Main St. and Helmer Ave,Dolgeville,Herkimer,New York,13329 +4,Preston Farmers’ Market,#1 Route 164,Preston,New London,Connecticut, +5,Quincy Farmers Market,0 Denis Ryan Parkway,Quincy,Norfolk,Massachusetts,2169 +6,Jefferson City Farmer's Market,000 Main Street,Jefferson City,Cole,Missouri,0 +7,Petaluma Evening Farmers' Market,1 2nd Street,Petaluma,Sonoma,California,94952 +8,Charlestown Farmers Market,"1 Austin Street, Thompson Square at Austin & Main Streets",Boston,,Massachusetts,2129 +9,Farmers Market at Christopher Newport University,1 Avenue of the Arts,Newport News,Newport News,Virginia,23606 From 3d18f50eb1e0dc2aa7975e33a574e6564bf457f8 Mon Sep 17 00:00:00 2001 From: Jenna Nichols Date: Thu, 22 Oct 2015 14:35:23 -0700 Subject: [PATCH 41/47] finished additional vendor methods --- lib/far_mar/vendor.rb | 12 ++++++++++++ spec/far_mar/vendor_spec.rb | 19 +++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/lib/far_mar/vendor.rb b/lib/far_mar/vendor.rb index e6e692b9..4a2ef49e 100644 --- a/lib/far_mar/vendor.rb +++ b/lib/far_mar/vendor.rb @@ -91,5 +91,17 @@ def self.revenue_by_date(date) return total_revenue end + def vendor_revenue_by_date(date) + date = Date.parse(date.to_s) + day_sales = self.sales.find_all do |sale| + date == sale.purchase_time.to_date + end + day_revenue = 0 + day_sales.each do |sale| + day_revenue = day_revenue + sale.amount + end + return day_revenue + end + end end diff --git a/spec/far_mar/vendor_spec.rb b/spec/far_mar/vendor_spec.rb index 62c10e19..5bb82eb4 100644 --- a/spec/far_mar/vendor_spec.rb +++ b/spec/far_mar/vendor_spec.rb @@ -7,6 +7,10 @@ @vendor = FarMar::Vendor.new(vendor_info) vendor2_info = ["2","Hamill, Kilback and Pfeffer","5","1"] @vendor2 = FarMar::Vendor.new(vendor2_info) + vendor7_info = ["7","Bechtelar Inc","4","2"] + @vendor7 = FarMar::Vendor.new(vendor7_info) + vendor8_info = ["8","Stamm Inc","2","2"] + @vendor8 = FarMar::Vendor.new(vendor8_info) vendor51_info = ["51","Bernier Inc","1","12"] @vendor51 = FarMar::Vendor.new(vendor51_info) end @@ -141,6 +145,21 @@ it "returns a number" do expect(FarMar::Vendor.revenue_by_date(@date)).to be_a(Fixnum) end + it "returns the total revenue" do + expect(FarMar::Vendor.revenue_by_date(@date)).to eq(9060582) + end + end + + describe "#vendor_revenue_by_date(date)" do + before :each do + @date = "2013-11-07" + end + it "returns a number" do + expect(@vendor7.vendor_revenue_by_date(@date)).to be_a(Fixnum) + end + it "returns the revenue for that date" do + expect(@vendor7.vendor_revenue_by_date(@date)).to eq(12377) + end end end From 59af043a11e30cacd57bdc0fd0a1e518877eb2a8 Mon Sep 17 00:00:00 2001 From: Jenna Nichols Date: Thu, 22 Oct 2015 15:13:28 -0700 Subject: [PATCH 42/47] finished part one optionals, LOOONG specs --- lib/far_mar/product.rb | 24 +++++++++++++- spec/far_mar/product_spec.rb | 26 +++++++++++++++ spec/far_mar/vendor_spec.rb | 62 ++++++++++++++++++------------------ 3 files changed, 80 insertions(+), 32 deletions(-) diff --git a/lib/far_mar/product.rb b/lib/far_mar/product.rb index 3a94f4a5..439bcbcb 100644 --- a/lib/far_mar/product.rb +++ b/lib/far_mar/product.rb @@ -17,7 +17,7 @@ def self.all @@product_array.push(new_product) end end - + return @@product_array end @@ -40,6 +40,15 @@ def sales return sales end + def product_revenue + product_revenue = 0 + sales = self.sales + sales.each do |sale| + product_revenue = product_revenue + sale.amount + end + return product_revenue + end + def number_of_sales return self.sales.length end @@ -51,5 +60,18 @@ def self.by_vendor(vendor_id) return vendor_products end + def self.most_revenue(n) + sorted_products = FarMar::Product.all.sort_by do |product| + product_revenue = 0 + product_sales = product.sales + product_sales.each do |sale| + product_revenue = product_revenue + sale.amount + end + product_revenue + end + sorted_products.reverse! + return sorted_products[0..n-1] + end + end end diff --git a/spec/far_mar/product_spec.rb b/spec/far_mar/product_spec.rb index 5ae6dc40..af03e867 100644 --- a/spec/far_mar/product_spec.rb +++ b/spec/far_mar/product_spec.rb @@ -66,6 +66,16 @@ end end + describe "#product_revenue" do + it "returns a number" do + expect(@product.product_revenue).to be_a(Fixnum) + end + it "calculates the total product revenue" do + expect(@product.product_revenue).to eq(38259) + expect(@product3.product_revenue).to eq(0) + end + end + describe "#number_of_sales" do it "returns a number" do expect(@product.number_of_sales).to be_a(Fixnum) @@ -88,5 +98,21 @@ end end + describe ".most_revenue(n)" do + before :each do + @n = 2 + end + it "returns a collection" do + expect(FarMar::Product.most_revenue(@n)).to be_an(Array) + end + it "returns a list of Products" do + expect(FarMar::Product.most_revenue(2)[0]).to be_an_instance_of(FarMar::Product) + expect(FarMar::Product.most_revenue(2)[1]).to be_an_instance_of(FarMar::Product) + end + it "is an ordered list" do + expect(FarMar::Product.most_revenue(@n)[0].product_revenue).to be >= FarMar::Product.most_revenue(2)[1].product_revenue if FarMar::Product.most_revenue(2).length > 1 + end + end + end end diff --git a/spec/far_mar/vendor_spec.rb b/spec/far_mar/vendor_spec.rb index 5bb82eb4..094121d6 100644 --- a/spec/far_mar/vendor_spec.rb +++ b/spec/far_mar/vendor_spec.rb @@ -106,37 +106,37 @@ end end - # describe ".most_revenue(n)" do - # before :each do - # @n = 2 - # end - # it "returns a collection" do - # expect(FarMar::Vendor.most_revenue(@n)).to be_an(Array) - # end - # it "returns a list of Vendors" do - # expect(FarMar::Vendor.most_revenue(2)[0]).to be_an_instance_of(FarMar::Vendor) - # expect(FarMar::Vendor.most_revenue(2)[1]).to be_an_instance_of(FarMar::Vendor) - # end - # it "returns an ranked list, sorted highest to lowest" do - # expect(FarMar::Vendor.most_revenue(2)[0].revenue).to be > FarMar::Vendor.most_revenue(2)[1].revenue if FarMar::Vendor.most_revenue(2).length > 1 - # end - # end - # - # describe ".most_items(n)" do - # before :each do - # @n = 2 - # end - # it "returns a collection" do - # expect(FarMar::Vendor.most_items(@n)).to be_an(Array) - # end - # it "returns a list of Vendors" do - # expect(FarMar::Vendor.most_items(@n)[0]).to be_an_instance_of(FarMar::Vendor) - # expect(FarMar::Vendor.most_items(@n)[1]).to be_an_instance_of(FarMar::Vendor) - # end - # it "returns a ranked list, sorted highest to lowest" do - # expect(FarMar::Vendor.most_items(2)[0].products.length).to be >= FarMar::Vendor.most_items(2)[1].products.length if FarMar::Vendor.most_items(2).length > 1 - # end - # end + describe ".most_revenue(n)" do + before :each do + @n = 2 + end + it "returns a collection" do + expect(FarMar::Vendor.most_revenue(@n)).to be_an(Array) + end + it "returns a list of Vendors" do + expect(FarMar::Vendor.most_revenue(2)[0]).to be_an_instance_of(FarMar::Vendor) + expect(FarMar::Vendor.most_revenue(2)[1]).to be_an_instance_of(FarMar::Vendor) + end + it "returns an ranked list, sorted highest to lowest" do + expect(FarMar::Vendor.most_revenue(2)[0].revenue).to be > FarMar::Vendor.most_revenue(2)[1].revenue if FarMar::Vendor.most_revenue(2).length > 1 + end + end + + describe ".most_items(n)" do + before :each do + @n = 2 + end + it "returns a collection" do + expect(FarMar::Vendor.most_items(@n)).to be_an(Array) + end + it "returns a list of Vendors" do + expect(FarMar::Vendor.most_items(@n)[0]).to be_an_instance_of(FarMar::Vendor) + expect(FarMar::Vendor.most_items(@n)[1]).to be_an_instance_of(FarMar::Vendor) + end + it "returns a ranked list, sorted highest to lowest" do + expect(FarMar::Vendor.most_items(2)[0].products.length).to be >= FarMar::Vendor.most_items(2)[1].products.length if FarMar::Vendor.most_items(2).length > 1 + end + end describe ".revenue_by_date(date)" do before :each do From 0c0cd52328286e261a4b00c56a17b04b740f316a Mon Sep 17 00:00:00 2001 From: Jenna Nichols Date: Thu, 22 Oct 2015 16:35:02 -0700 Subject: [PATCH 43/47] updated vendor code --- lib/far_mar/vendor.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/far_mar/vendor.rb b/lib/far_mar/vendor.rb index 4a2ef49e..02633e40 100644 --- a/lib/far_mar/vendor.rb +++ b/lib/far_mar/vendor.rb @@ -83,7 +83,7 @@ def self.most_items(n) def self.revenue_by_date(date) date = Date.parse(date.to_s) total_revenue = 0 - day_sales = FarMar::Sale.all.each do |sale| + FarMar::Sale.all.each do |sale| if sale.purchase_time.to_date == date total_revenue = total_revenue + sale.amount end From 994b20391eade9773358ca93e93b87b00bf4ee7e Mon Sep 17 00:00:00 2001 From: Jenna Nichols Date: Fri, 23 Oct 2015 09:27:18 -0700 Subject: [PATCH 44/47] added comments about long specs --- spec/far_mar/product_spec.rb | 32 +++++++------ spec/far_mar/sale_spec.rb | 1 + spec/far_mar/vendor_spec.rb | 90 ++++++++++++++++++++---------------- 3 files changed, 67 insertions(+), 56 deletions(-) diff --git a/spec/far_mar/product_spec.rb b/spec/far_mar/product_spec.rb index af03e867..9b44f16c 100644 --- a/spec/far_mar/product_spec.rb +++ b/spec/far_mar/product_spec.rb @@ -98,21 +98,23 @@ end end - describe ".most_revenue(n)" do - before :each do - @n = 2 - end - it "returns a collection" do - expect(FarMar::Product.most_revenue(@n)).to be_an(Array) - end - it "returns a list of Products" do - expect(FarMar::Product.most_revenue(2)[0]).to be_an_instance_of(FarMar::Product) - expect(FarMar::Product.most_revenue(2)[1]).to be_an_instance_of(FarMar::Product) - end - it "is an ordered list" do - expect(FarMar::Product.most_revenue(@n)[0].product_revenue).to be >= FarMar::Product.most_revenue(2)[1].product_revenue if FarMar::Product.most_revenue(2).length > 1 - end - end + ### can comment out below method to speed up specs ### + # describe ".most_revenue(n)" do + # before :each do + # @n = 2 + # end + # it "returns a collection" do + # expect(FarMar::Product.most_revenue(@n)).to be_an(Array) + # end + # it "returns a list of Products" do + # expect(FarMar::Product.most_revenue(2)[0]).to be_an_instance_of(FarMar::Product) + # expect(FarMar::Product.most_revenue(2)[1]).to be_an_instance_of(FarMar::Product) + # end + # it "is an ordered list" do + # expect(FarMar::Product.most_revenue(@n)[0].product_revenue).to be >= FarMar::Product.most_revenue(2)[1].product_revenue if FarMar::Product.most_revenue(2).length > 1 + # end + # end + ### can comment out above method to speed up specs ### end end diff --git a/spec/far_mar/sale_spec.rb b/spec/far_mar/sale_spec.rb index d2148dc8..b89920ac 100644 --- a/spec/far_mar/sale_spec.rb +++ b/spec/far_mar/sale_spec.rb @@ -64,6 +64,7 @@ end end + describe ".between(beginning_time, end_time)" do before :each do @beginning_time = DateTime.strptime("2013-11-06 08:35:40 -0800", "%Y-%m-%d %H:%M:%S %z") diff --git a/spec/far_mar/vendor_spec.rb b/spec/far_mar/vendor_spec.rb index 094121d6..6735bc37 100644 --- a/spec/far_mar/vendor_spec.rb +++ b/spec/far_mar/vendor_spec.rb @@ -106,49 +106,57 @@ end end - describe ".most_revenue(n)" do - before :each do - @n = 2 - end - it "returns a collection" do - expect(FarMar::Vendor.most_revenue(@n)).to be_an(Array) - end - it "returns a list of Vendors" do - expect(FarMar::Vendor.most_revenue(2)[0]).to be_an_instance_of(FarMar::Vendor) - expect(FarMar::Vendor.most_revenue(2)[1]).to be_an_instance_of(FarMar::Vendor) - end - it "returns an ranked list, sorted highest to lowest" do - expect(FarMar::Vendor.most_revenue(2)[0].revenue).to be > FarMar::Vendor.most_revenue(2)[1].revenue if FarMar::Vendor.most_revenue(2).length > 1 - end - end + ### can comment out below method to speed up specs ### + # describe ".most_revenue(n)" do + # before :each do + # @n = 2 + # end + # it "returns a collection" do + # expect(FarMar::Vendor.most_revenue(@n)).to be_an(Array) + # end + # it "returns a list of Vendors" do + # expect(FarMar::Vendor.most_revenue(2)[0]).to be_an_instance_of(FarMar::Vendor) + # expect(FarMar::Vendor.most_revenue(2)[1]).to be_an_instance_of(FarMar::Vendor) + # end + # it "returns an ranked list, sorted highest to lowest" do + # expect(FarMar::Vendor.most_revenue(2)[0].revenue).to be > FarMar::Vendor.most_revenue(2)[1].revenue if FarMar::Vendor.most_revenue(2).length > 1 + # end + # end + ### can comment out above method to speed up specs ### - describe ".most_items(n)" do - before :each do - @n = 2 - end - it "returns a collection" do - expect(FarMar::Vendor.most_items(@n)).to be_an(Array) - end - it "returns a list of Vendors" do - expect(FarMar::Vendor.most_items(@n)[0]).to be_an_instance_of(FarMar::Vendor) - expect(FarMar::Vendor.most_items(@n)[1]).to be_an_instance_of(FarMar::Vendor) - end - it "returns a ranked list, sorted highest to lowest" do - expect(FarMar::Vendor.most_items(2)[0].products.length).to be >= FarMar::Vendor.most_items(2)[1].products.length if FarMar::Vendor.most_items(2).length > 1 - end - end - describe ".revenue_by_date(date)" do - before :each do - @date = "2013-11-07" - end - it "returns a number" do - expect(FarMar::Vendor.revenue_by_date(@date)).to be_a(Fixnum) - end - it "returns the total revenue" do - expect(FarMar::Vendor.revenue_by_date(@date)).to eq(9060582) - end - end + ### can comment out below method to speed up specs ### + # describe ".most_items(n)" do + # before :each do + # @n = 2 + # end + # it "returns a collection" do + # expect(FarMar::Vendor.most_items(@n)).to be_an(Array) + # end + # it "returns a list of Vendors" do + # expect(FarMar::Vendor.most_items(@n)[0]).to be_an_instance_of(FarMar::Vendor) + # expect(FarMar::Vendor.most_items(@n)[1]).to be_an_instance_of(FarMar::Vendor) + # end + # it "returns a ranked list, sorted highest to lowest" do + # expect(FarMar::Vendor.most_items(2)[0].products.length).to be >= FarMar::Vendor.most_items(2)[1].products.length if FarMar::Vendor.most_items(2).length > 1 + # end + # end + ### can comment out above method to speed up specs ### + + ### can comment out below method to speed up specs ### + # describe ".revenue_by_date(date)" do + # before :each do + # @date = "2013-11-07" + # end + # it "returns a number" do + # expect(FarMar::Vendor.revenue_by_date(@date)).to be_a(Fixnum) + # end + # it "returns the total revenue" do + # expect(FarMar::Vendor.revenue_by_date(@date)).to eq(9060582) + # end + # end + ### can comment out above method to speed up specs ### + describe "#vendor_revenue_by_date(date)" do before :each do From 0655982ce448855a17f7b0d61f2925d880430a09 Mon Sep 17 00:00:00 2001 From: Jenna Nichols Date: Fri, 23 Oct 2015 09:43:55 -0700 Subject: [PATCH 45/47] updated support folder --- support/sample_markets.csv | 9 --------- 1 file changed, 9 deletions(-) delete mode 100644 support/sample_markets.csv diff --git a/support/sample_markets.csv b/support/sample_markets.csv deleted file mode 100644 index 1ddb3585..00000000 --- a/support/sample_markets.csv +++ /dev/null @@ -1,9 +0,0 @@ -1,People's Co-op Farmers Market,30th and Burnside,Portland,Multnomah,Oregon,97202 -2,Silverdale Farmers Market,98383,Silverdale,Kitsap,Washington,98383 -3,Dolgeville Farmer's Market,(Parking Lot) Between Main St. and Helmer Ave,Dolgeville,Herkimer,New York,13329 -4,Preston Farmers’ Market,#1 Route 164,Preston,New London,Connecticut, -5,Quincy Farmers Market,0 Denis Ryan Parkway,Quincy,Norfolk,Massachusetts,2169 -6,Jefferson City Farmer's Market,000 Main Street,Jefferson City,Cole,Missouri,0 -7,Petaluma Evening Farmers' Market,1 2nd Street,Petaluma,Sonoma,California,94952 -8,Charlestown Farmers Market,"1 Austin Street, Thompson Square at Austin & Main Streets",Boston,,Massachusetts,2129 -9,Farmers Market at Christopher Newport University,1 Avenue of the Arts,Newport News,Newport News,Virginia,23606 From 2da0a0517825056aa7653a61ceeeda477b6ff439 Mon Sep 17 00:00:00 2001 From: Jenna Nichols Date: Fri, 23 Oct 2015 14:14:20 -0700 Subject: [PATCH 46/47] changed code to speed up specs --- lib/far_mar/product.rb | 6 +-- lib/far_mar/sale.rb | 23 +++++++-- lib/far_mar/vendor.rb | 6 +-- spec/far_mar/product_spec.rb | 32 ++++++------- spec/far_mar/sale_spec.rb | 1 - spec/far_mar/vendor_spec.rb | 90 ++++++++++++++++-------------------- 6 files changed, 79 insertions(+), 79 deletions(-) diff --git a/lib/far_mar/product.rb b/lib/far_mar/product.rb index 439bcbcb..88ae7f1b 100644 --- a/lib/far_mar/product.rb +++ b/lib/far_mar/product.rb @@ -34,10 +34,8 @@ def vendor end def sales - sales = FarMar::Sale.all.find_all do |sale| - sale.product_id == self.id - end - return sales + sales_hash = FarMar::Sale.sales_by_product + return sales_hash[@id] end def product_revenue diff --git a/lib/far_mar/sale.rb b/lib/far_mar/sale.rb index cdc81c75..af346be4 100644 --- a/lib/far_mar/sale.rb +++ b/lib/far_mar/sale.rb @@ -11,16 +11,31 @@ def initialize(sale_info) end def self.all - @@sale_array ||= [] + return sales_by_product.values.flatten + end + + def self.sales_by_product + @@sales_by_product ||= Hash.new { |hash,key| hash[key] = [] } - if @@sale_array == [] + if @@sales_by_product.empty? CSV.read("./support/sales.csv").each do |sale| new_sale = FarMar::Sale.new(sale) - @@sale_array.push(new_sale) + @@sales_by_product[sale[4].to_i].push(new_sale) end end + return @@sales_by_product + end + + def self.sales_by_vendor + @@sales_by_vendor ||= Hash.new { |hash,key| hash[key] = [] } - return @@sale_array + if @@sales_by_vendor.empty? + CSV.read("./support/sales.csv").each do |sale| + new_sale = FarMar::Sale.new(sale) + @@sales_by_vendor[sale[3].to_i].push(new_sale) + end + end + return @@sales_by_vendor end def self.find(id) diff --git a/lib/far_mar/vendor.rb b/lib/far_mar/vendor.rb index 02633e40..e37d67c9 100644 --- a/lib/far_mar/vendor.rb +++ b/lib/far_mar/vendor.rb @@ -42,10 +42,8 @@ def products end def sales - sales = FarMar::Sale.all.find_all do |sale| - sale.vendor_id == self.id - end - return sales + sales_hash = FarMar::Sale.sales_by_vendor + return sales_hash[@id] end def revenue diff --git a/spec/far_mar/product_spec.rb b/spec/far_mar/product_spec.rb index 9b44f16c..af03e867 100644 --- a/spec/far_mar/product_spec.rb +++ b/spec/far_mar/product_spec.rb @@ -98,23 +98,21 @@ end end - ### can comment out below method to speed up specs ### - # describe ".most_revenue(n)" do - # before :each do - # @n = 2 - # end - # it "returns a collection" do - # expect(FarMar::Product.most_revenue(@n)).to be_an(Array) - # end - # it "returns a list of Products" do - # expect(FarMar::Product.most_revenue(2)[0]).to be_an_instance_of(FarMar::Product) - # expect(FarMar::Product.most_revenue(2)[1]).to be_an_instance_of(FarMar::Product) - # end - # it "is an ordered list" do - # expect(FarMar::Product.most_revenue(@n)[0].product_revenue).to be >= FarMar::Product.most_revenue(2)[1].product_revenue if FarMar::Product.most_revenue(2).length > 1 - # end - # end - ### can comment out above method to speed up specs ### + describe ".most_revenue(n)" do + before :each do + @n = 2 + end + it "returns a collection" do + expect(FarMar::Product.most_revenue(@n)).to be_an(Array) + end + it "returns a list of Products" do + expect(FarMar::Product.most_revenue(2)[0]).to be_an_instance_of(FarMar::Product) + expect(FarMar::Product.most_revenue(2)[1]).to be_an_instance_of(FarMar::Product) + end + it "is an ordered list" do + expect(FarMar::Product.most_revenue(@n)[0].product_revenue).to be >= FarMar::Product.most_revenue(2)[1].product_revenue if FarMar::Product.most_revenue(2).length > 1 + end + end end end diff --git a/spec/far_mar/sale_spec.rb b/spec/far_mar/sale_spec.rb index b89920ac..d2148dc8 100644 --- a/spec/far_mar/sale_spec.rb +++ b/spec/far_mar/sale_spec.rb @@ -64,7 +64,6 @@ end end - describe ".between(beginning_time, end_time)" do before :each do @beginning_time = DateTime.strptime("2013-11-06 08:35:40 -0800", "%Y-%m-%d %H:%M:%S %z") diff --git a/spec/far_mar/vendor_spec.rb b/spec/far_mar/vendor_spec.rb index 6735bc37..094121d6 100644 --- a/spec/far_mar/vendor_spec.rb +++ b/spec/far_mar/vendor_spec.rb @@ -106,57 +106,49 @@ end end - ### can comment out below method to speed up specs ### - # describe ".most_revenue(n)" do - # before :each do - # @n = 2 - # end - # it "returns a collection" do - # expect(FarMar::Vendor.most_revenue(@n)).to be_an(Array) - # end - # it "returns a list of Vendors" do - # expect(FarMar::Vendor.most_revenue(2)[0]).to be_an_instance_of(FarMar::Vendor) - # expect(FarMar::Vendor.most_revenue(2)[1]).to be_an_instance_of(FarMar::Vendor) - # end - # it "returns an ranked list, sorted highest to lowest" do - # expect(FarMar::Vendor.most_revenue(2)[0].revenue).to be > FarMar::Vendor.most_revenue(2)[1].revenue if FarMar::Vendor.most_revenue(2).length > 1 - # end - # end - ### can comment out above method to speed up specs ### - - - ### can comment out below method to speed up specs ### - # describe ".most_items(n)" do - # before :each do - # @n = 2 - # end - # it "returns a collection" do - # expect(FarMar::Vendor.most_items(@n)).to be_an(Array) - # end - # it "returns a list of Vendors" do - # expect(FarMar::Vendor.most_items(@n)[0]).to be_an_instance_of(FarMar::Vendor) - # expect(FarMar::Vendor.most_items(@n)[1]).to be_an_instance_of(FarMar::Vendor) - # end - # it "returns a ranked list, sorted highest to lowest" do - # expect(FarMar::Vendor.most_items(2)[0].products.length).to be >= FarMar::Vendor.most_items(2)[1].products.length if FarMar::Vendor.most_items(2).length > 1 - # end - # end - ### can comment out above method to speed up specs ### + describe ".most_revenue(n)" do + before :each do + @n = 2 + end + it "returns a collection" do + expect(FarMar::Vendor.most_revenue(@n)).to be_an(Array) + end + it "returns a list of Vendors" do + expect(FarMar::Vendor.most_revenue(2)[0]).to be_an_instance_of(FarMar::Vendor) + expect(FarMar::Vendor.most_revenue(2)[1]).to be_an_instance_of(FarMar::Vendor) + end + it "returns an ranked list, sorted highest to lowest" do + expect(FarMar::Vendor.most_revenue(2)[0].revenue).to be > FarMar::Vendor.most_revenue(2)[1].revenue if FarMar::Vendor.most_revenue(2).length > 1 + end + end - ### can comment out below method to speed up specs ### - # describe ".revenue_by_date(date)" do - # before :each do - # @date = "2013-11-07" - # end - # it "returns a number" do - # expect(FarMar::Vendor.revenue_by_date(@date)).to be_a(Fixnum) - # end - # it "returns the total revenue" do - # expect(FarMar::Vendor.revenue_by_date(@date)).to eq(9060582) - # end - # end - ### can comment out above method to speed up specs ### + describe ".most_items(n)" do + before :each do + @n = 2 + end + it "returns a collection" do + expect(FarMar::Vendor.most_items(@n)).to be_an(Array) + end + it "returns a list of Vendors" do + expect(FarMar::Vendor.most_items(@n)[0]).to be_an_instance_of(FarMar::Vendor) + expect(FarMar::Vendor.most_items(@n)[1]).to be_an_instance_of(FarMar::Vendor) + end + it "returns a ranked list, sorted highest to lowest" do + expect(FarMar::Vendor.most_items(2)[0].products.length).to be >= FarMar::Vendor.most_items(2)[1].products.length if FarMar::Vendor.most_items(2).length > 1 + end + end + describe ".revenue_by_date(date)" do + before :each do + @date = "2013-11-07" + end + it "returns a number" do + expect(FarMar::Vendor.revenue_by_date(@date)).to be_a(Fixnum) + end + it "returns the total revenue" do + expect(FarMar::Vendor.revenue_by_date(@date)).to eq(9060582) + end + end describe "#vendor_revenue_by_date(date)" do before :each do From 7b57967e7e967ecb663642d48854d86d6c80dec7 Mon Sep 17 00:00:00 2001 From: Jenna Nichols Date: Fri, 23 Oct 2015 14:23:48 -0700 Subject: [PATCH 47/47] updated hash creation in Sale class --- lib/far_mar/sale.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/far_mar/sale.rb b/lib/far_mar/sale.rb index af346be4..42229263 100644 --- a/lib/far_mar/sale.rb +++ b/lib/far_mar/sale.rb @@ -20,7 +20,7 @@ def self.sales_by_product if @@sales_by_product.empty? CSV.read("./support/sales.csv").each do |sale| new_sale = FarMar::Sale.new(sale) - @@sales_by_product[sale[4].to_i].push(new_sale) + @@sales_by_product[new_sale.product_id].push(new_sale) end end return @@sales_by_product @@ -32,7 +32,7 @@ def self.sales_by_vendor if @@sales_by_vendor.empty? CSV.read("./support/sales.csv").each do |sale| new_sale = FarMar::Sale.new(sale) - @@sales_by_vendor[sale[3].to_i].push(new_sale) + @@sales_by_vendor[new_sale.vendor_id].push(new_sale) end end return @@sales_by_vendor