From ab9d6d16e3d2d77dccd387dc0d490423aefabf1c Mon Sep 17 00:00:00 2001 From: Sarah Date: Wed, 21 Oct 2015 13:44:46 -0700 Subject: [PATCH 1/5] Primary Requirements --- lib/far_mar/market.rb | 45 +++++++++++++++++++++++++++++++++++- lib/far_mar/product.rb | 28 ++++++++++++++++++++++ lib/far_mar/sale.rb | 30 ++++++++++++++++++++++++ lib/far_mar/vendor.rb | 31 +++++++++++++++++++++++++ spec/far_mar/market_spec.rb | 17 +++++++++++++- spec/far_mar/product_spec.rb | 18 +++++++++++++-- spec/far_mar/sale_spec.rb | 15 +++++++++++- spec/far_mar/vendor_spec.rb | 15 +++++++++++- 8 files changed, 193 insertions(+), 6 deletions(-) diff --git a/lib/far_mar/market.rb b/lib/far_mar/market.rb index 7469f1e0..8b6fc46c 100644 --- a/lib/far_mar/market.rb +++ b/lib/far_mar/market.rb @@ -1,5 +1,48 @@ +require "pry" +require "csv" module FarMar class Market - + attr_accessor :id, :name, :address, :city, :county, :state, :zip + attr_reader :object + + def initialize (id, name, address, city, county, state, zip) + @id = id.to_i + @name = name + @address = address + @city = city + @county = county + @state = state + @zip = zip + @object = + + end + + + def self.all + market_array = [] + farmar_data = CSV.read("./support/markets.csv") + farmar_data.each do |csv| + @m = Market.new(csv[0], csv[1], csv[2], csv[3], csv[4], csv[5], csv[6]) + market_array.push(@m) + end + return market_array + end + + def self.find(id) + farmar_data = Market.all + farmar_data.find do |data| + if data.id == id + return data + end + end + end + + def initialize + object = + end + + + + end end diff --git a/lib/far_mar/product.rb b/lib/far_mar/product.rb index 8efc48d2..13560949 100644 --- a/lib/far_mar/product.rb +++ b/lib/far_mar/product.rb @@ -1,5 +1,33 @@ +require "pry" +require "csv" + module FarMar class Product + attr_accessor :id, :name, :vendor_id + + def initialize (id, name, vendor_id) + @id = id.to_i + @name = name + @vendor_id = vendor_id.to_i + end + + def self.all + product_array =[] + product_data = CSV.read("./support/products.csv") + product_data.each do |csv| + @p = Product.new(csv[0], csv[1],csv[2]) + product_array.push(@p) + end + return product_array + end + def self.find(id) + product_data = Product.all + product_data.find do |data| + if data.id == id + return data + end + end + end end end diff --git a/lib/far_mar/sale.rb b/lib/far_mar/sale.rb index 10e3780e..d34852f0 100644 --- a/lib/far_mar/sale.rb +++ b/lib/far_mar/sale.rb @@ -1,4 +1,34 @@ +require "pry" +require "csv" module FarMar class Sale + attr_accessor :id, :Amount, :Purchase_time, :vendor_id, :product_id + + def initialize (id, amount, purchase_time, vendor_id, product_id) + @id = id.to_i + @amount = amount.to_i + @purchase_time = purchase_time.to_i + @vnedor_id = vendor_id + @product_id = product_id.to_i + end + + def self.all + sale_array = [] + sale_data = CSV.read("./support/sales.csv") + sale_data.each do |csv| + @s = Sale.new(csv[0], csv[1], csv[2], csv[3], csv[4]) + sale_array.push(@s) + end + return sale_array + end + + def self.find(id) + sale_data = Sale.all + sale_data.find do |data| + if data.id == id + return data + end + end + end end end diff --git a/lib/far_mar/vendor.rb b/lib/far_mar/vendor.rb index bfe19c33..188efc0e 100644 --- a/lib/far_mar/vendor.rb +++ b/lib/far_mar/vendor.rb @@ -1,5 +1,36 @@ +require "pry" +require "csv" + module FarMar class Vendor + attr_accessor :id, :name, :no_of_employees, :market_id + + def initialize (id, name, no_of_employees, market_id) + @id = id.to_i + @name = name + @no_of_employees = no_of_employees.to_i + @market_id = market_id.to_i + end + + def self.all + vendor_array = [] + vendor_data = CSV.read("./support/vendors.csv") + vendor_data.each do |csv| + @v = Vendor.new(csv[0], csv[1], csv[2], csv[3]) + vendor_array.push(@v) + end + return vendor_array + end + + def self.find(id) + vendor_data = Vendor.all + vendor_data.find do |data| + if data.id == id + return data + end + end + end + end end diff --git a/spec/far_mar/market_spec.rb b/spec/far_mar/market_spec.rb index 204b458c..85eb296a 100644 --- a/spec/far_mar/market_spec.rb +++ b/spec/far_mar/market_spec.rb @@ -2,7 +2,7 @@ describe FarMar::Market do before :each do - @market = FarMar::Market.new + @market = FarMar::Market.new("id","name","city","county","state","zip","address") end describe "new market instance" do @@ -10,4 +10,19 @@ expect(@market).to be_an_instance_of FarMar::Market end end + + + + describe "return a collection of market instances described in CVS" do + it "returns all of the accounts" do + expect(FarMar::Market.all).to be_an_instance_of Array + end + end + + describe "return one account" do + it "returns one account" do + expect(FarMar::Market.find(1).id).to eq 1 + end + end + end diff --git a/spec/far_mar/product_spec.rb b/spec/far_mar/product_spec.rb index 5cd77cc9..7a32f518 100644 --- a/spec/far_mar/product_spec.rb +++ b/spec/far_mar/product_spec.rb @@ -2,12 +2,26 @@ describe FarMar::Product do before :each do - @product = FarMar::Product.new + @product = FarMar::Product.new("id", "name", "vendor_id") end - describe "new product instance; .new" do + describe "new product instance" do it "creats a new product instance" do expect(@product).to be_an_instance_of FarMar::Product end end + + + describe "return a collection of product instances described in CVS" do + it "returns all of the accounts" do + expect(FarMar::Product.all).to be_an_instance_of Array + end + end + + describe "return one account" do + it "returns one account" do + expect(FarMar::Product.find(1).id).to eq 1 + end + end + end diff --git a/spec/far_mar/sale_spec.rb b/spec/far_mar/sale_spec.rb index e1a7aa52..2e1c2dd0 100644 --- a/spec/far_mar/sale_spec.rb +++ b/spec/far_mar/sale_spec.rb @@ -2,7 +2,7 @@ describe FarMar::Sale do before :each do - @sale = FarMar::Sale.new + @sale = FarMar::Sale.new("id", "amount", "purchase_time", "vendor_id", "product_id") end describe "new sale instance" do @@ -10,4 +10,17 @@ expect(@sale).to be_an_instance_of FarMar::Sale end end + describe "return a collection of sale instances described in CVS" do + it "returns all of the accounts" do + expect(FarMar::Sale.all).to be_an_instance_of Array + end + end + + describe "return one account" do + it "returns one account" do + expect(FarMar::Sale.find(1).id).to eq 1 + end + end + + end diff --git a/spec/far_mar/vendor_spec.rb b/spec/far_mar/vendor_spec.rb index fb7ee7b9..be42d7b0 100644 --- a/spec/far_mar/vendor_spec.rb +++ b/spec/far_mar/vendor_spec.rb @@ -2,7 +2,7 @@ describe FarMar::Vendor do before :each do - @vendor = FarMar::Vendor.new + @vendor = FarMar::Vendor.new("id", "name", "no_of_employees", "market_id") end describe "new vendor instance" do @@ -10,4 +10,17 @@ expect(@vendor).to be_an_instance_of FarMar::Vendor end end + + + describe "return a collection of market instances described in CVS" do + it "returns all of the accounts" do + expect(FarMar::Vendor.all).to be_an_instance_of Array + end + end + + describe "return one account" do + it "returns one account" do + expect(FarMar::Vendor.find(1).id).to eq 1 + end + end end From 3020bd2ba2791f71fd79c301ab896e07a76e3639 Mon Sep 17 00:00:00 2001 From: Sarah Date: Wed, 21 Oct 2015 16:14:45 -0700 Subject: [PATCH 2/5] some Additional MarMar::Vendor Methods --- lib/far_mar/market.rb | 16 +++++++--------- lib/far_mar/vendor.rb | 12 ++++++++++++ spec/far_mar/market_spec.rb | 6 ++++++ spec/far_mar/vendor_spec.rb | 16 +++++++++++++++- 4 files changed, 40 insertions(+), 10 deletions(-) diff --git a/lib/far_mar/market.rb b/lib/far_mar/market.rb index 8b6fc46c..79555503 100644 --- a/lib/far_mar/market.rb +++ b/lib/far_mar/market.rb @@ -3,9 +3,9 @@ module FarMar class Market attr_accessor :id, :name, :address, :city, :county, :state, :zip - attr_reader :object - def initialize (id, name, address, city, county, state, zip) + + def initialize(id, name, address, city, county, state, zip) @id = id.to_i @name = name @address = address @@ -13,7 +13,7 @@ def initialize (id, name, address, city, county, state, zip) @county = county @state = state @zip = zip - @object = + end @@ -37,12 +37,10 @@ def self.find(id) end end - def initialize - object = + def get_vendor + FarMar::Vendor.all.find_all do |vendor| + vendor.market_id == @id + end end - - - - end end diff --git a/lib/far_mar/vendor.rb b/lib/far_mar/vendor.rb index 188efc0e..b1ac6d4d 100644 --- a/lib/far_mar/vendor.rb +++ b/lib/far_mar/vendor.rb @@ -30,6 +30,18 @@ def self.find(id) end end end + def get_market + FarMar::Market.all.find do |market| + market.id == @id + end + end + + def get_products + FarMar::Product.all.find_all do |product| + product.vendor_id == @id + end + + end end diff --git a/spec/far_mar/market_spec.rb b/spec/far_mar/market_spec.rb index 85eb296a..fccbbf80 100644 --- a/spec/far_mar/market_spec.rb +++ b/spec/far_mar/market_spec.rb @@ -25,4 +25,10 @@ end end + describe ".get_vendor" do + it "returns all accounts with same market id" do + expect(@market.get_vendor).to be_an Array + end + end + end diff --git a/spec/far_mar/vendor_spec.rb b/spec/far_mar/vendor_spec.rb index be42d7b0..dbb7db24 100644 --- a/spec/far_mar/vendor_spec.rb +++ b/spec/far_mar/vendor_spec.rb @@ -2,7 +2,7 @@ describe FarMar::Vendor do before :each do - @vendor = FarMar::Vendor.new("id", "name", "no_of_employees", "market_id") + @vendor = FarMar::Vendor.new("1","Feil-Farrell","8","1") end describe "new vendor instance" do @@ -23,4 +23,18 @@ expect(FarMar::Vendor.find(1).id).to eq 1 end end + + + describe ".get_market" do + it "returns all accounts withth same vendor id" do + expect(@vendor.get_market).to be_an_instance_of FarMar::Market + end + end + + + describe ".get_products" do + it "returns all accounts with the same vendor id" do + expect(@vendor.get_products).to be_an_instance_of Array + end + end end From 579eab7d0d17916f574f7c198814c04d92328627 Mon Sep 17 00:00:00 2001 From: Sarah Date: Thu, 22 Oct 2015 13:57:40 -0700 Subject: [PATCH 3/5] Additional FarMar::Vendor Methods complete --- lib/far_mar/sale.rb | 4 ++-- lib/far_mar/vendor.rb | 20 +++++++++++++++++++- spec/far_mar/vendor_spec.rb | 18 ++++++++++++++++++ 3 files changed, 39 insertions(+), 3 deletions(-) diff --git a/lib/far_mar/sale.rb b/lib/far_mar/sale.rb index d34852f0..a820bb23 100644 --- a/lib/far_mar/sale.rb +++ b/lib/far_mar/sale.rb @@ -2,13 +2,13 @@ require "csv" module FarMar class Sale - attr_accessor :id, :Amount, :Purchase_time, :vendor_id, :product_id + attr_accessor :id, :amount, :purchase_time, :vendor_id, :product_id def initialize (id, amount, purchase_time, vendor_id, product_id) @id = id.to_i @amount = amount.to_i @purchase_time = purchase_time.to_i - @vnedor_id = vendor_id + @vendor_id = vendor_id.to_i @product_id = product_id.to_i end diff --git a/lib/far_mar/vendor.rb b/lib/far_mar/vendor.rb index b1ac6d4d..74d1784f 100644 --- a/lib/far_mar/vendor.rb +++ b/lib/far_mar/vendor.rb @@ -32,7 +32,7 @@ def self.find(id) end def get_market FarMar::Market.all.find do |market| - market.id == @id + market.id == @market_id end end @@ -40,9 +40,27 @@ def get_products FarMar::Product.all.find_all do |product| product.vendor_id == @id end + end + def get_sales + FarMar::Sale.all.find_all do |sale| + sale.vendor_id == @id + end end + def revenue + total = 0 + get_sales.each do |sale| + total = total + sale.amount + end + return total + end + def self.by_market(market_id) + FarMar::Vendor.all.find_all do |vendor| + vendor.market_id == market_id + + end + end end end diff --git a/spec/far_mar/vendor_spec.rb b/spec/far_mar/vendor_spec.rb index dbb7db24..8e26d652 100644 --- a/spec/far_mar/vendor_spec.rb +++ b/spec/far_mar/vendor_spec.rb @@ -37,4 +37,22 @@ expect(@vendor.get_products).to be_an_instance_of Array end end + + describe ".get_sales" do + it "returns all accounts with the vendor id" do + expect(@vendor.get_sales).to be_an_instance_of Array + end + end + + describe "revenue" do + it "returns the amount of vendor sales in cents" do + expect(@vendor.revenue).to eq 38259 + end + + describe ".by_market" do + it "returns all of the vendors with the given market_id" do + expect(FarMar::Vendor.by_market(2)).to be_an_instance_of Array + end + end + end end From d5f6e267ec24bd11e937d4c2ecce93249a2e8bc7 Mon Sep 17 00:00:00 2001 From: Sarah Date: Fri, 23 Oct 2015 13:49:03 -0700 Subject: [PATCH 4/5] Additional FarMar::Sale Methods --- lib/far_mar/product.rb | 30 ++++++++++++++++++++++++++++++ lib/far_mar/vendor.rb | 3 +++ spec/far_mar/product_spec.rb | 21 ++++++++++++++++++++- spec/far_mar/vendor_spec.rb | 2 +- support/products.csv | 2 +- 5 files changed, 55 insertions(+), 3 deletions(-) diff --git a/lib/far_mar/product.rb b/lib/far_mar/product.rb index 13560949..b07bfa02 100644 --- a/lib/far_mar/product.rb +++ b/lib/far_mar/product.rb @@ -29,5 +29,35 @@ def self.find(id) end end end + + def get_vendor + FarMar::Vendor.all.find_all do |vendor| + vendor.id == @vendor_id + end + end + + def get_sales + FarMar::Sale.all.find_all do |sale| + sale.vendor_id == @id + end + end + + def number_of_sales + total = 0 + FarMar::Sale.all.each do |each_sale| + if each_sale.product_id == id + total = total + 1 + end + end + return total + end + + def self.by_vendor(vendor_id) + self.all.find_all do |product| + product.vendor_id == vendor_id + end + + end + end end diff --git a/lib/far_mar/vendor.rb b/lib/far_mar/vendor.rb index 74d1784f..9b8a61f4 100644 --- a/lib/far_mar/vendor.rb +++ b/lib/far_mar/vendor.rb @@ -30,6 +30,7 @@ def self.find(id) end end end + def get_market FarMar::Market.all.find do |market| market.id == @market_id @@ -61,6 +62,8 @@ def self.by_market(market_id) vendor.market_id == market_id end + + end end end diff --git a/spec/far_mar/product_spec.rb b/spec/far_mar/product_spec.rb index 7a32f518..a86c267a 100644 --- a/spec/far_mar/product_spec.rb +++ b/spec/far_mar/product_spec.rb @@ -2,9 +2,10 @@ describe FarMar::Product do before :each do - @product = FarMar::Product.new("id", "name", "vendor_id") + @product = FarMar::Product.new("1", "name", "1") end + describe "new product instance" do it "creats a new product instance" do expect(@product).to be_an_instance_of FarMar::Product @@ -24,4 +25,22 @@ end end + describe "get_vendor" do + it "returns all account with the same vendor id" do + expect(@product.get_vendor).to be_an Array + end + end + + describe "number_of_sales" do + it "returns the number of the product has been sold" do + expect(@product.number_of_sales).to eq 7 + end + end + + describe "self.by_vendor" do + it "returns returns all of the products with the given vendor_id" do + expect(FarMar::Product.all.find_all) + end +end + end diff --git a/spec/far_mar/vendor_spec.rb b/spec/far_mar/vendor_spec.rb index 8e26d652..cb0a4d2e 100644 --- a/spec/far_mar/vendor_spec.rb +++ b/spec/far_mar/vendor_spec.rb @@ -26,7 +26,7 @@ describe ".get_market" do - it "returns all accounts withth same vendor id" do + it "returns all accounts with the same market id" do expect(@vendor.get_market).to be_an_instance_of FarMar::Market end end diff --git a/support/products.csv b/support/products.csv index 92794f1c..2cd50214 100644 --- a/support/products.csv +++ b/support/products.csv @@ -23,7 +23,7 @@ 23,Calm Carrots,10 24,Fierce Beef,10 25,Helpless Bread,10 -26,Yummy Bread,10 +26,Yummy Bread,10 27,Broken Beets,10 28,Quiet Honey,11 29,Crazy Fish,11 From cf0bf6ece6f8f7bdd660919f3fd0bb3cf07068db Mon Sep 17 00:00:00 2001 From: Sarah Date: Fri, 23 Oct 2015 15:40:41 -0700 Subject: [PATCH 5/5] Additional FarMar::Sale Methods --- lib/far_mar/sale.rb | 25 ++++++++++++++++++++++++- spec/far_mar/sale_spec.rb | 11 +++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/lib/far_mar/sale.rb b/lib/far_mar/sale.rb index a820bb23..b80b0ebf 100644 --- a/lib/far_mar/sale.rb +++ b/lib/far_mar/sale.rb @@ -7,7 +7,7 @@ class Sale def initialize (id, amount, purchase_time, vendor_id, product_id) @id = id.to_i @amount = amount.to_i - @purchase_time = purchase_time.to_i + @purchase_time = DateTime.strptime(purchase_time, "%Y-%m-%d %H:%M:%S %z") @vendor_id = vendor_id.to_i @product_id = product_id.to_i end @@ -30,5 +30,28 @@ def self.find(id) end end end + def get_vendor + FarMar::Vendor.all.find_all do |vendor| + vendor.id == @vendor_id + end + end + + def get_product + FarMar::Product.all.each do |product| + if product.id == product_id + return product + end + end + end + + def self.between(beginning_time, end_time) + array = [] + self.all.find_all do |sale_times| + if sale_times.purchase_time >= beginning_time && sale_times.purchase_time <= end_time + array.push(sale_times) + end + end + return array + end end end diff --git a/spec/far_mar/sale_spec.rb b/spec/far_mar/sale_spec.rb index 2e1c2dd0..d926ff52 100644 --- a/spec/far_mar/sale_spec.rb +++ b/spec/far_mar/sale_spec.rb @@ -22,5 +22,16 @@ end end + describe "get_vendor" do + it "returns vendor instance ralated to sale" do + expect(@sale.get_vendor).to be_an Array + end + end + + describe "get_product" do + it "returns product instance related to sale" do + expect(@sale.get_product). to be_an Array + end + end end