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

Shari Meggs - FarMar #61

Open
wants to merge 48 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
f7fb657
set up the foundation of the project structure with little to no code…
SSBinks Sep 6, 2016
5994af5
I updated the specs to have initialize tests and connect only to help…
SSBinks Sep 6, 2016
031b995
All the lib files have classes connected to FarMar and have the basic…
SSBinks Sep 6, 2016
4f2d6dc
The far mar file has the othe files required
SSBinks Sep 6, 2016
412f3e6
Rakefile updated
SSBinks Sep 6, 2016
6860a8a
This has three added test that cover self.all and self.find
SSBinks Sep 6, 2016
41177f9
updated the file with two methods self.all and self.find. Both are fu…
SSBinks Sep 6, 2016
d4d613b
I added a test to make sure vendors is working and completed the method
SSBinks Sep 7, 2016
66e3aa3
Added a test to make sure that vendors was made up of instances of Ve…
SSBinks Sep 7, 2016
0fbf0a6
Updated tests and code to have functionality to pass market_id and re…
SSBinks Sep 7, 2016
1035285
Added the all and find methods with the tests for product
SSBinks Sep 7, 2016
6a5eac6
Added the all and find methods with the test for sale
SSBinks Sep 7, 2016
f8c5a06
added a new test for the market method. It should be an instance of F…
SSBinks Sep 7, 2016
996853b
Created the market method to return a market object. This satisfies t…
SSBinks Sep 7, 2016
ec981ee
Added two tests to make sure market returned an instance of Market an…
SSBinks Sep 7, 2016
173fe53
added the by vendor method and assosicated tests
SSBinks Sep 8, 2016
3400097
added self_by market and products methods and associated tests
SSBinks Sep 8, 2016
50c2d5d
Had to update this file so that there were appropriate readers. I had…
SSBinks Sep 8, 2016
ea022ec
updated a test for sales method to look if value was an array
SSBinks Sep 8, 2016
3c71df6
Added the sales method to return the correct instances
SSBinks Sep 8, 2016
073a8fe
Just deleted a space
SSBinks Sep 8, 2016
5cc43cd
Was using wrong CSV file so it was not pulling correct data
SSBinks Sep 8, 2016
7483dbd
Had a puts in one of the tests that was distracting. Took it out
SSBinks Sep 8, 2016
fc8b749
added revenue test that looked at Fixnum and not equalling 0.
SSBinks Sep 8, 2016
ed6de06
Realized I was not testing for a specific vend ID
SSBinks Sep 8, 2016
5583b0f
Updated test to use the sales method in vendor so that the total woul…
SSBinks Sep 8, 2016
ab0c843
updated test for sales so that it returns a type of Object
SSBinks Sep 8, 2016
8b23969
added the sales method
SSBinks Sep 8, 2016
dd9db06
moved a require line so coverage looked at correct folders
SSBinks Sep 8, 2016
369ae40
updated the let line to better test the value of an ID
SSBinks Sep 8, 2016
24974c9
I changed one of the numbers in the let
SSBinks Sep 8, 2016
1b5cbb7
I deleted a puts I had previously been using in debugging
SSBinks Sep 8, 2016
7d0b1a2
I added a test for number of sales to be equal to 58
SSBinks Sep 8, 2016
d03a15a
added a number of sales method which satisfies the test
SSBinks Sep 8, 2016
d1dcdd3
I had to update the number of sales I wanted to return as I accidenta…
SSBinks Sep 8, 2016
923bbc1
created simple instance of tests for vendor and product
SSBinks Sep 8, 2016
a66ce47
Added methods for vendor and product
SSBinks Sep 8, 2016
019efd5
added the chronic require so that I could use the gem in sale
SSBinks Sep 8, 2016
41ebc5d
I forgot to add a method for vendor so I made a test for the instance
SSBinks Sep 8, 2016
579ef77
Created a vendor method
SSBinks Sep 8, 2016
23e964f
made two tests one made sure that the between method returned an arra…
SSBinks Sep 8, 2016
adcdba3
made the between method and included the Chronic parse. Played around…
SSBinks Sep 8, 2016
fa1c98f
wrote three tests for between and changes the values in test to all b…
SSBinks Sep 9, 2016
cdeef19
rewrote my between method as the parsing was working but the loops we…
SSBinks Sep 9, 2016
2dea9d7
Auto Indent
SSBinks Sep 9, 2016
98091d6
I changed the ID in some tests to make them match up to market
SSBinks Sep 9, 2016
3cd2596
Added a test for products
SSBinks Sep 9, 2016
1dac5f6
Added products method
SSBinks Sep 9, 2016
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
coverage/
7 changes: 7 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require 'rake/testtask'

Rake::TestTask.new do |t|
t.test_files = FileList['specs/*_spec.rb']
end

task default: :test
7 changes: 7 additions & 0 deletions far_mar.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require 'csv'
require './lib/farmar_market'
require './lib/farmar_product'
require './lib/farmar_sale'
require './lib/farmar_vendor'
require 'chronic'
module FarMar; end
51 changes: 51 additions & 0 deletions lib/farmar_market.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
require 'csv'

module FarMar
class Market
attr_reader :id, :name, :address, :city, :state
def initialize (id, name, address, city, county, state, zip)
@id = id
@name = name
@address = address
@city = city
@county = county
@state = state
@zip = zip
end

def self.all
markets = {}
farm_mrkt = []
CSV.open('support/markets.csv', 'r'). each do |place|
markets[place[0]] = place[1..6]
id = place[0].to_i
name = place[1]
address = place[2]
city = place[3]
county = place[4]
state = place[5]
zip = place[6]
farm_mrkt << self.new(id, name, address, city, county, state, zip)
end
return farm_mrkt
end
def self.find(id)
id_find = self.all
id_find.each do |i|
if i.id == id
return i
end
end
end
def vendors
FarMar::Vendor.by_market(@id)
end
def products
products = []
vendors.each do |x|
products << FarMar::Product.by_vendor(x.vend_id)
end
products.flatten!
end
end
end
51 changes: 51 additions & 0 deletions lib/farmar_product.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
class FarMar::Product
attr_reader :id, :name, :vend_id
def initialize (id, name, vend_id)
@id = id
@name = name
@vend_id = vend_id
end
def self.all
products = {}
merch = []
CSV.open('support/products.csv', 'r').each do |line|
products[line[0]] = line[1..2]
id = line[0].to_i
name = line[1]
vend = line[2].to_i
merch << self.new(id, name, vend)
end
return merch
end

def self.find(id)
find_id = self.all
find_id.each do |i|
if i.id == id
return i
end
end
end

def vendor
FarMar::Vendor.find(@vend_id)
end

def self.by_vendor(vendor_id)
prod_search = self.all
prod_search.find_all do |i|
i.vend_id == vendor_id
end
end

def sales
FarMar::Sale.all.find_all do |i|
i.prod_id == @id
end
end

def number_of_sales
sales.count
end

end
55 changes: 55 additions & 0 deletions lib/farmar_sale.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@

class FarMar::Sale
attr_reader :id, :amount, :purch_time, :vend_id, :prod_id
def initialize(id, amount, purch_time, vend, prod)
@id = id
@amount = amount
@purch_time = purch_time
@vend_id = vend
@prod_id = prod
end

def self.all
sales = {}
discount = []
CSV.open('support/sales.csv', 'r').each do |line|
sales[line[0]] = line[1..4]
id = line[0].to_i
amount = line[1].to_i
purch_time = line[2]
vend = line[3].to_i
prod = line[4].to_i
discount << self.new(id, amount, purch_time, vend, prod)
end
return discount
end

def self.find(id)
find_id = self.all
find_id.each do |i|
if i.id == id
return i
end
end
end

def vendor
FarMar::Vendor.find(@vend_id)
end
def product
FarMar::Product.find(@prod_id)
end

def self.between(begin_time, end_time)
times = []
time = Time.now
start = Chronic.parse(begin_time)
fin = Chronic.parse(end_time)
all.each do |i|
time = Chronic.parse(i.purch_time)
if start < time && time < fin
times << i
end
end
end
end
59 changes: 59 additions & 0 deletions lib/farmar_vendor.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
class FarMar::Vendor
attr_reader :vend_id, :name, :num, :market_id
def initialize(id, name, num, market_id)
@vend_id = id
@name = name
@empl_num = num
@market_id = market_id
end

def self.all
vendors = {}
farm_vend = []
CSV.open('support/vendors.csv', 'r').each do |vend|
vendors[vend[0]] = vend[1..3]
id = vend[0].to_i
name = vend[1]
num = vend[2]
market_id = vend[3].to_i
farm_vend << self.new(id, name, num, market_id)
end
return farm_vend
end

def self.find(id)
find_id = self.all
find_id.each do |i|
if i.vend_id == id
return i
end
end
end
def self.by_market(market_id)

vend_search = self.all
vend_search.find_all do |i|
i.market_id == market_id
end
end
def market
FarMar::Market.find(@market_id)
end

def products
FarMar::Product.by_vendor(@vend_id)
end
def sales
sales = FarMar::Sale.all
sales.find_all do |x|
x.vend_id == @vend_id
end
end
def revenue
sale = []
sales.map! do |a|
sale << a.amount
end
sale.reduce(:+)
end
end
50 changes: 50 additions & 0 deletions specs/market_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
require_relative 'spec_helper'


describe FarMar::Market do
let(:cap_hill) {FarMar::Market.new( 1, "Judy", "723 Herman ave", "Skokie", "Cook", "Il", "60076")}
describe "#initialize" do
it "can create a new instance of Market" do
cap_hill.must_be_instance_of(FarMar::Market)
end

it "should have an id property" do
cap_hill.must_respond_to(:id)
end

end
describe "self.all" do
it "should return an array" do
FarMar::Market.all.must_be_kind_of(Array)
end
end

describe "self.find(id)" do
it "should return the id that was passed through" do
FarMar::Market.find(1).id.must_equal(1)
end

it "should return the state the corresponds to the id" do
FarMar::Market.find(290).state.must_equal("North Carolina")
end
end
describe "vendors" do
it "should return an array" do

cap_hill.vendors.must_be_kind_of(Array)
end
it "should be an instance of vendor" do
vendor = cap_hill.vendors

vendor[0].must_be_instance_of(FarMar::Vendor)
end
end
describe "#products" do
it "should return a collection of FarMar:: Product instances" do
cap_hill.products.each do |x|
x.must_be_instance_of(FarMar::Product)
end
end
end

end
43 changes: 43 additions & 0 deletions specs/product_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
require_relative 'spec_helper'

describe FarMar::Product do
let(:sam) {FarMar::Product.new(58, "Jane", 19)}
describe "#initialize" do
it "can create a new instance of Product" do
sam.must_be_instance_of(FarMar::Product)
end
end
describe "self.all" do
it "should return an array" do
FarMar::Product.all.must_be_kind_of(Array)
end
end
describe "self.find(id)" do
it "should return the id that was passed through" do
FarMar::Product.find(1).id.must_equal(1)
end
end
describe "#vendor" do
it "returns an instance of FarMar ::Vendor" do
sam.vendor.must_be_instance_of(FarMar::Vendor)
end
end
describe "self.by_vendor(vendor_id)" do
it "returns the vendors of a given vendor id" do

FarMar::Product.by_vendor(19).each do |x|
x.vend_id.must_equal(19)
end
end
end
describe "#sales" do
it "will return a collection of sales instances based on the product id" do
sam.sales.must_be_kind_of(Object)
end
end
describe "#number_of_sales" do
it "can return the number of times a product has been sold" do
sam.number_of_sales.must_equal(5)
end
end
end
45 changes: 45 additions & 0 deletions specs/sale_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
require_relative 'spec_helper'

describe FarMar::Sale do
let(:sam){FarMar::Sale.new(19, 15, "2013-11-06 20:44:00", 19, 58)}
describe "#initialize" do

it "can create a new instance of Sale" do
sam.must_be_instance_of(FarMar::Sale)
end
end

describe "self.all" do
it "should return an array" do
FarMar::Sale.all.must_be_kind_of(Array)
end
end
describe "self.find(id)" do
it "should return the id that was passed through" do
FarMar::Sale.find(1).id.must_equal(1)
end
end
describe "#vendor" do
it "will return an instance of Farm::Vendor" do
sam.vendor.must_be_instance_of(FarMar::Vendor)
end
end
describe "#product" do
it "returns an instance of FarMar::Product" do
sam.product.must_be_instance_of(FarMar::Product)
end
end
describe "self.between(begin_time, end_time)" do
it "will return FarMar:Sale instances" do
FarMar::Sale.between("2013-11-11 11:29:52 -0800", "2013-11-11 12:00:00 -0800").must_be_kind_of(Object)
end
it "will not include dates outside of the range" do
FarMar::Sale.between("2013-11-11 11:29:52 -0800", "2013-11-11 12:00:00 -0800")
sam.purch_time.wont_include("2013-11-13 01:48:15 -0800")
end
it "will not include dates outside of the range" do
FarMar::Sale.between("2013-11-11 11:29:52 -0800", "2013-11-11 12:00:00 -0800")
sam.purch_time.wont_include("2013-11-07 04:34:56 -0800")
end
end
end
13 changes: 13 additions & 0 deletions specs/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
require 'simplecov'

SimpleCov.start

require 'minitest'
require 'minitest/spec'
require "minitest/autorun"
require "minitest/reporters"
require 'minitest/pride'
#These are all the things about mini test that we are using
Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new

require_relative '../far_mar'
Loading