Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Arh/master #34

Open
wants to merge 42 commits into
base: arh/master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
38ea371
Made working initialize methods for the Market and Product classes
lacuchilla Oct 20, 2015
1f43d39
Working initialize methods for Sale and Vendor classes.
lacuchilla Oct 20, 2015
378b73e
Got the self.all method for the Market class to work.
lacuchilla Oct 20, 2015
e3790e8
Working self.all method for the Product class.
lacuchilla Oct 20, 2015
e166fe2
Working self.all method for the Sale class.
lacuchilla Oct 20, 2015
f6fc4b3
Working self.all method for Vendor class.
lacuchilla Oct 20, 2015
61dafb5
Added working self.find method in Market class and corrected self.all…
lacuchilla Oct 21, 2015
8cdf1c6
Added working self.find(id) method and corrected self.all method to r…
lacuchilla Oct 21, 2015
93b0636
Added working self.find(id) method to the Sale class. Fixed self.all …
lacuchilla Oct 21, 2015
bfd8ef5
Added working self.find(id) method to Vendor class. Fixed self.all me…
lacuchilla Oct 21, 2015
bae3581
Got a working initialize method test for the Market class using insta…
lacuchilla Oct 21, 2015
64f6520
Added working initalize spec for the Product class.
lacuchilla Oct 21, 2015
e4cb6cd
Added working initialize spec for Sale class and modified @purchase t…
lacuchilla Oct 21, 2015
9f88e4f
Added working initialize rspec for the Vendor class.
lacuchilla Oct 21, 2015
5b5e6ff
added a #self.all method to the Market class that returns all instanc…
lacuchilla Oct 21, 2015
b2f42d0
Got working self.all spec tests for the Product, Sale, and Vendor cla…
lacuchilla Oct 21, 2015
0f5e6d2
Added working self.all rspec with two tests that check if it returns …
lacuchilla Oct 21, 2015
a87ff3c
Added working self.all rspec for Vendor class with two tests.
lacuchilla Oct 21, 2015
6a63720
Added working rspec with two tests for the self.all method in the Sal…
lacuchilla Oct 21, 2015
ea5c475
Corrected descriptions in it line to be non file specific. All tests …
lacuchilla Oct 21, 2015
99d7d0b
Added working self.find(id) rspec with two tests.
lacuchilla Oct 21, 2015
fca722f
Added working self.find(id) tests to market_spec.rb
lacuchilla Oct 21, 2015
e226113
Added working self.find(id) method to the Product class. All tests pa…
lacuchilla Oct 21, 2015
f4b08a5
Added working self.find(id) method to sale_spec.rb. All tests working.
lacuchilla Oct 21, 2015
5bf7512
Wrote working vendors method for Market class and fixed spec file tes…
lacuchilla Oct 21, 2015
bcffc7f
Added working market method to the vendor class and two spec tests.
lacuchilla Oct 22, 2015
c9c2b61
Added working products method to the Vendor class and added some tests.
lacuchilla Oct 22, 2015
65861fb
Added working sales method to the Vendor class and added a test.
lacuchilla Oct 22, 2015
fb5f5e5
Added working vendor method to the Product method. Rspec tests are no…
lacuchilla Oct 22, 2015
92a9ac5
Added working sales method to Product class.
lacuchilla Oct 22, 2015
f355d94
fixed vendor_spec.rb file. 90% code coverage.
lacuchilla Oct 22, 2015
a2af6e6
Added working product method for sale class.
lacuchilla Oct 22, 2015
350f21d
Added tests for product method in sale spec. All tests passing.
lacuchilla Oct 22, 2015
20192f6
Added working revenue method.
lacuchilla Oct 23, 2015
2da2f50
Added working self.by_market class method to the Vendor class.
lacuchilla Oct 23, 2015
f80aeee
Added working self.by_vendor(vendor_id) method to the Product class.
lacuchilla Oct 23, 2015
762e2c1
Added working self.between(beginning_time, end_time)method
lacuchilla Oct 23, 2015
f3b1823
Added working spec for .self.between(beginning_time, end_time) method.
lacuchilla Oct 23, 2015
1034490
Added working self.find method to sale class. All specs passing.
lacuchilla Oct 23, 2015
27edf3f
Added working product spec test. All tests passing.
lacuchilla Oct 23, 2015
80696d7
Added working rspec tests for self.find(id) method in the product_spe…
lacuchilla Oct 23, 2015
490bf41
Added working #sales test for Product class in the product_spec.rb file.
lacuchilla Oct 23, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions lib/far_mar/market.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,45 @@
require 'csv'

module FarMar
class Market
attr_accessor :id, :name, :address, :city, :county, :state, :zip
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
end

def self.all
#returns a collection of Market instances, representing all of the markets described in the CSV
market_array = []
read_file = CSV.read("./support/markets.csv")
read_file.each do |market|
list_of_markets = FarMar::Market.new(market[0], market[1], market[2], market[3], market[4], market[5], market[6])
market_array.push(list_of_markets)
end
return market_array
end

def self.find(id)
#returns an instance of Market where the value in the id field of the CSV file matches the passed parameter
self.all.find {|i| i.id == id}
end

def vendors
#returns a collection of FarMar::Vendor instances that are associated with the market by the market_id field
vendor_array = []
vendor_list = FarMar::Vendor.all
vendor_list.find_all do |i|
if i.market_id == id
vendor_array.push(i)
end
end
return vendor_array
end

end
end
67 changes: 67 additions & 0 deletions lib/far_mar/product.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,71 @@
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
#returns a collection of product instances, representing all of the products described in the CSV
product_array = []
product_file = CSV.read("./support/products.csv")
product_file.each do |product|
list_of_products = FarMar::Product.new(product[0], product[1], product[2])
product_array.push(list_of_products)
end
return product_array
end

def self.find(id)
#returns an instance of Product where the value in the id field of the CSV file matches the passed parameter
all.find {|i| i.id == id}
end

def vendor
# returns the FarMar::Market instance that is associated with this vendor
# using the FarMar::Vendor market_id field
# vendor_array = []
# vendor_list = FarMar::Product.all
# vendor_list.find_all do |i|
# if i.id == vendor_id
# vendor_array.push(i)
# end
# end
# return vendor_array

vendor_list = FarMar::Vendor.all
vendor_list.find do |vendor|
vendor.id == vendor_id
end
end

def sales
#sales - returns a collection
#of FarMar::Sale instances that are associated
#using the FarMar::Sale product_id field.
sales_array = []
sales_list = FarMar::Sale.all
sales_list.find_all do |i|
if i.product_id == id
sales_array.push(i)
end
end
return sales_array
end

def self.by_vendor(vendor_id)
#returns all of the products with the given vendor_id
products_sold_by_a_vendor_array = []
product_list = FarMar::Product.all
product_list.find_all do |product|
if product.vendor_id == vendor_id
products_sold_by_a_vendor_array.push(product)
end
end
return products_sold_by_a_vendor_array
end

end
end
63 changes: 63 additions & 0 deletions lib/far_mar/sale.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,67 @@
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_s
@vendor_id = vendor_id.to_i
@product_id = product_id.to_i
end

def self.all
#returns a collection of sale instances, representing all of the sales described in the CSV
sale_array = []
CSV.read("./support/sales.csv").each do |sale|
list_of_sales = Sale.new(sale[0], sale[1], sale[2], sale[3], sale[4])
sale_array.push(list_of_sales)
end
return sale_array
end

def self.find(id)
#self.find(id) - returns an instance of Sale where the value of the id field
#in the CSV matches the passed parameter.
all.find {|i| i.id == id}
end

def vendor
# returns the FarMar::Market instance that is associated with this vendor
# using the FarMar::Vendor market_id field
vendor_list = FarMar::Vendor.all
vendor_list.find do |vendor|
vendor.id == vendor_id
end
end

def product
#product - returns the FarMar::Product
# instance that is associated with this sale using the FarMar::Sale product_id field
product_list = FarMar::Product.all
product_list.find do |product|
product.id == product_id
end
end


def self.between(beginning_time, end_time)
#returns a collection of FarMar::Sale
#objects where the purchase time is between the two times given as arguments
sales_between_times_array = []
list_of_sales = FarMar::Sale.all
list_of_sales.find_all do |sale|
if (beginning_time < sale.purchase_time) && (sale.purchase_time < end_time)
sales_between_times_array.push(sale)
end
end
return sales_between_times_array
end
# @begin = DateTime.strptime("2013-11-06 08:35:40 -0800", "%Y-%m-%d %H:%M:%S %z")
# @end = DateTime.strptime("2013-11-13 08:35:16 -0800", "%Y-%m-%d
#
# list_of_sales.each do |sale_object|
# sale_object.purchase_time > beginning_time && sale_object.purchase_time < end_time


end
end
77 changes: 77 additions & 0 deletions lib/far_mar/vendor.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,81 @@
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
@market_id = market_id.to_i
end

def self.all
#returns a collection of vendor instances, representing all of the vendors described in the CSV
vendor_array = []
CSV.read("./support/vendors.csv").each do |vendor|
list_of_vendors = Vendor.new(vendor[0], vendor[1], vendor[2], vendor[3])
vendor_array.push(list_of_vendors)
end
return vendor_array
end

def self.find(id)
self.all.find {|i| i.id == id}
end

def market
# returns the FarMar::Market instance that is associated with this vendor
# using the FarMar::Vendor market_id field
market_array = []
market_list = FarMar::Market.all
market_list.find_all do |i|
if i.id == market_id
market_array.push(i)
end
end
return market_array
end

def products
product_array = []
product_list = FarMar::Product.all
product_list.find_all do |i|
if i.vendor_id == id
product_array.push(i)
end
end
return product_array
end

def sales
sales_array = []
sales_list = FarMar::Sale.all
sales_list.find_all do |i|
if i.vendor_id == id
sales_array.push(i)
end
end
return sales_array
end

def revenue
total_amount = 0
sales.each do |sale|
total_amount += sale.amount
end
return total_amount
end

def self.by_market(market_id)
#returns all of the vendors with the given market_id
vendors_in_a_market_array = []
vendor_list = FarMar::Vendor.all
vendor_list.find_all do |vendor|
if vendor.market_id == market_id
vendors_in_a_market_array.push(vendor)
end
end
return vendors_in_a_market_array
end

end
end
32 changes: 31 additions & 1 deletion spec/far_mar/market_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,42 @@

describe FarMar::Market do
before :each do
@market = FarMar::Market.new
@market = FarMar::Market.new("14", "Hartford Farmers Market", "1 Block North of Highway 60 on Rural Street","Hartford","Washington", "Wisconsin", "53027")
@market_2 = FarMar::Market.new("500", "Montefiore Medical Center Farmers Market_Thursday", "111 E. 210th Street", "Bronx", "Bronx", "New York","10467")
end

context "initializing" do
it "returns a market object" do
expect(@market).to be_an_instance_of FarMar::Market
end
end

context ".self.all" do
it "returns an array" do
expect(FarMar::Market.all().class).to be Array
end
it "returns instances of all lines in the csv" do
expect(FarMar::Market.all().length).to eq 500
end
end

context ".self.find(id)" do
it "returns the right instance" do
expect(FarMar::Market.find(14).name).to eq "Hartford Farmers Market"
end

it "returns an instance with the same id as the value in the CSV file" do
expect(@market.id).to eq 14
expect(@market_2.id).to eq 500
end
end

context "#vendors" do
it "returns a collection" do
expect(@market.vendors.class).to eq Array
end
it "is a collection of Vendor instances in Far::Mar" do
expect(@market.vendors.length).to eq 8
end
end
end
45 changes: 44 additions & 1 deletion spec/far_mar/product_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,55 @@

describe FarMar::Product do
before :each do
@product = FarMar::Product.new
@product = FarMar::Product.new(12, "Gorgeous Fish", 6)
@product_2 = FarMar::Product.new(8193, "Cruel Beef", 2690)
end

context "initializing" do
it "returns a product object" do
expect(@product).to be_an_instance_of FarMar::Product
end
end

context ".self.all" do
it "returns an array" do
expect(FarMar::Product.all().class).to be Array
end
it "returns instances of all lines in the csv" do
expect(FarMar::Product.all().length).to eq 8193
end
end

context ".self.find(id)" do
it "returns an instance of Product" do
expect(FarMar::Product.find(12)).to be_an_instance_of FarMar::Product
end

it "returns the right instance" do
expect(FarMar::Product.find(12).name).to eq "Gorgeous Fish"
end
it "returns an instance with the same id as the value in the CSV file" do
expect(@product.id).to eq 12
expect(@product_2.id).to eq 8193
end
end

context "#vendor" do
it "returns an instance of Vendor" do
expect(@product.vendor).to be_an_instance_of FarMar::Vendor
end
end

context "#sales" do
it "returns a collection of FarMar::Sale instances" do
expect(@product_2.sales.length).to eq 2
end
end

context ".self.by_vendor(vendor_id)" do
it "returns all of the products with a given vendor id" do
expect(FarMar::Product.by_vendor(6).length).to eq 3
end
end

end
Loading