Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
971b9d9
Created a crap-load of files and specs
nurlywhirly Sep 6, 2016
55e6626
baseline file creations complete for first pull request
nurlywhirly Sep 6, 2016
d5e34ca
WiP commit for lunchtime on Tuesday
nurlywhirly Sep 6, 2016
23c2ef5
Completed self.all and self.find methods for all classes
nurlywhirly Sep 6, 2016
3e1c370
some more language cleanup for self.all and self.find methods
nurlywhirly Sep 6, 2016
ccd295e
Fixed all the require_relatives and NameErrors
nurlywhirly Sep 7, 2016
327fcb9
Added products method to Vendor class and copied tests from Market cl…
nurlywhirly Sep 7, 2016
bbf2391
Added Vendor methods sales and revenue.
nurlywhirly Sep 7, 2016
ad364b0
Fixing the sales CSV so the unique identifiers are actually unique. D…
nurlywhirly Sep 7, 2016
0731d0f
Added self method by_market into Vendor class
nurlywhirly Sep 7, 2016
8369fc3
Fixing a little thing on by_market self method in Vendor class
nurlywhirly Sep 7, 2016
b901dce
Tiny fixins of language before moving onto Product class
nurlywhirly Sep 7, 2016
fda2ab7
Added vendor method to Product class
nurlywhirly Sep 7, 2016
c0f51a9
Added sales and number_of_sales methods to Product class
nurlywhirly Sep 8, 2016
cbc5b96
Added self.by_vendor method to the Product class
nurlywhirly Sep 8, 2016
4b97b97
Added vendor method to Sale class
nurlywhirly Sep 8, 2016
dc1464f
Added product method and self.between(time1,time2) methods to Sale class
nurlywhirly Sep 8, 2016
a4799f3
Fixed calculation for self.between method bc it was very wrong also a…
nurlywhirly Sep 8, 2016
17b184d
Added ArgumentError to self.between Sale class
nurlywhirly Sep 8, 2016
82d931b
Fixed ArgumentError in self.between Sale class so if provided date ov…
nurlywhirly Sep 8, 2016
7f96574
Changed all date/time comparisons to DateTime objects because Kari fo…
nurlywhirly Sep 8, 2016
cd2735f
Fixed sales_spec because I forgot to change class names when I copied…
nurlywhirly Sep 8, 2016
d72cdad
Added another ArgError to self.between in Sale class to guarantee beg…
nurlywhirly Sep 9, 2016
1b477a1
Added self.search enhancement method to Market class
nurlywhirly Sep 9, 2016
0930ff0
Added an Argument Error to self.search method in Market class
nurlywhirly Sep 9, 2016
7f4fe8b
Added products method to Market class (optional)
nurlywhirly Sep 9, 2016
25b993d
Added preferred_vendor method to Market class (optional
nurlywhirly 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
38 changes: 38 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
*.gem
*.rbc
/.config
/coverage/
/specs/coverage
/InstalledFiles
/pkg/
/spec/reports/
/test/tmp/
/test/version_tmp/
/tmp/
/specs/.DS_Store
.DS_Store

## Specific to RubyMotion:
.dat*
.repl_history
build/

## Documentation cache and generated files:
/.yardoc/
/_yardoc/
/doc/
/rdoc/

## Environment normalisation:
/.bundle/
/vendor/bundle
/lib/bundler/man/

# for a library or gem, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# Gemfile.lock
# .ruby-version
# .ruby-gemset

# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
.rvmrc
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,10 @@ Each sale belongs to a vendor __AND__ a product. The `vendor_id` and `product_id
1. You'll be working as an individual on this project.
1. Fork the Ada-C6 repo to your Github account.
1. Clone your fork to your projects directory, and `cd` into the cloned repo.
1. Create a _gemset_ for your project
<!-- SKIP 1. Create a _gemset_ for your project
1. `$ echo 2.3.0 > .ruby-version`
1. `$ echo farmar > .ruby-gemset`
1. `$ cd .`
1. `$ cd .` -->
1. Install necessary gems via Terminal:
- `$ gem install minitest-reporters`
- `$ gem install simplecov`
Expand Down Expand Up @@ -154,4 +154,4 @@ Each sale belongs to a vendor __AND__ a product. The `vendor_id` and `product_id

#### Try some inheritance or some composition
- __Inheritance:__ Create a new _class_ that defines the shared/duplicated methods (i.e., `find`, `all`). Update your data classes to _inherit_ this _class_ .
- __Composition with a Mixin:__ Create a new _module_ that defines the duplicated methods (i.e., `find`, `all`). Update your data classes to _mixin_ this _module_.
- __Composition with a Mixin:__ Create a new _module_ that defines the duplicated methods (i.e., `find`, `all`). Update your data classes to _mixin_ this _module_.
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
32 changes: 32 additions & 0 deletions far_mar.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
require 'csv'


require_relative 'lib/market.rb'
require_relative 'lib/vendor.rb'
require_relative 'lib/product.rb'
require_relative 'lib/sale.rb'


module FarMar
##### Testing self methods
# puts Market.search("and")
#
##### Testing instance methods
market = FarMar::Market.new(1,"Test Market","123 Main St","King", "Seattle", "WA", "98125")
puts market.preferred_vendor
#
##### Testing DateTime craziness
# date = DateTime.parse("2013-11-08 04:31:41 -0800")
#
# puts date.class
#
# puts Sale.between("1001-11-08 04:31:41 -0800","2013-11-08 16:36:03 -0800").length
#
##### Sales sorted by date for my own info
# all = Sale.all.map do |k, v|
# v.purchase_time
# end
#
# puts all.sort

end
79 changes: 79 additions & 0 deletions lib/market.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
require 'csv'

module FarMar
class Market
attr_reader :id, :name, :st_addy, :city, :county, :st, :zip

def initialize(id, name, st_addy, city, county, st, zip)
@id = id
@name = name
@st_addy = st_addy
@city = city
@county = county
@st = st
@zip = zip
end

def self.all
all_markets = {}
CSV.read("/Users/nurl/ada/homework/FarMar/support/markets.csv").each do |line|
all_markets[line[0].to_i] = self.new(line[0].to_i,line[1],line[2],line[3],line[4],line[5],line[6])
end
return all_markets
end

def self.find(id)
all_markets = self.all

if all_markets.has_key?(id)
return all_markets[id]
else
raise ArgumentError.new("We do not have a market with that ID.")
end
end

def self.search(search_term)
search_results = all.keep_if do |k, v|
v.name.downcase.include?(" " + search_term.downcase + " ")
end

if search_results.length > 1
return search_results
else
raise ArgumentError.new("There are no markets with \"#{search_term}\" in their name")
end
end

def vendors
all_vendors = FarMar::Vendor.all

all_vendors.delete_if do |k, v|
v.market_id != @id
end
end

def products
prdts_ary = vendors.map do |k, v|
v.products.map do |ke, va|
va
end
end

prdts_ary.flatten
end

def preferred_vendor
all_revenues = vendors.map do |k, v|
v.revenue
end

max_value = all_revenues.max

vendors.keep_if do |k, v|
return v if v.revenue == max_value
end
end

end

end
54 changes: 54 additions & 0 deletions lib/product.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
require 'csv'

module FarMar
class Product
attr_reader :id, :product, :vendor_id

def initialize(id, product, vendor_id)
@id = id
@product = product
@vendor_id = vendor_id
end

def self.all
all_products = {}
CSV.read("/Users/nurl/ada/homework/FarMar/support/products.csv").each do |line|
all_products[line[0].to_i] = self.new(line[0].to_i,line[1],line[2].to_i)
end
return all_products
end

def self.find(id)
if all.has_key?(id)
return all[id]
else
raise ArgumentError.new("We do not have a product with that ID.")
end
end

def self.by_vendor(vendor_id)
all.delete_if do |k, v|
v.vendor_id != vendor_id
end
end

def vendor
all_vendors = FarMar::Vendor.all
return all_vendors[@id]
end

def sales
all_sales = FarMar::Sale.all

all_sales.delete_if do |k, v|
v.product_id != @id
end

return all_sales
end

def number_of_sales
return sales.length
end
end
end
65 changes: 65 additions & 0 deletions lib/sale.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
require 'csv'

module FarMar
class Sale
attr_reader :id, :amount, :purchase_time, :vendor_id, :product_id

def initialize(id, amount, purchase_time, vendor_id, product_id)
@id = id
@amount = amount
@purchase_time = purchase_time
@vendor_id = vendor_id
@product_id = product_id
end

def self.all
all_sales = {}
CSV.read("/Users/nurl/ada/homework/FarMar/support/sales.csv").each do |line|
all_sales[line[0].to_i] = self.new(line[0].to_i,line[1].to_i,line[2],line[3].to_i,line[4].to_i)
end
return all_sales
end

def self.find(id)
if all.has_key?(id)
return all[id]
else
raise ArgumentError.new("We do not have a sale with that ID.")
end
end

def self.string_to_date(time)
DateTime.parse(time)
end

def self.between(beginning_time, end_time)
beginning_time = string_to_date(beginning_time)
end_time = string_to_date(end_time)

hash = {}
all.each do |k, v|
hash[v] = string_to_date(v.purchase_time)
end

raise ArgumentError.new("You must give a beginning time that is earlier than an end time") if beginning_time > end_time

raise ArgumentError.new("These dates are beyond the date range in our database") if (beginning_time < hash.values.min && end_time < hash.values.min ) || (beginning_time > hash.values.max && end_time > hash.values.max)

hash.delete_if do |k, v|
v < beginning_time || v > end_time
end

return hash.keys
end

def vendor
all_vendors = FarMar::Vendor.all
return all_vendors[@id]
end

def product
all_products = FarMar::Product.all
return all_products[@id]
end
end
end
70 changes: 70 additions & 0 deletions lib/vendor.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
require 'csv'

module FarMar
class Vendor
attr_reader :id, :name, :num_empls, :market_id

def initialize(id, name, num_empls, market_id)
@id = id
@name = name
@num_empls = num_empls
@market_id = market_id
end

def self.all
all_vendors = {}
CSV.read("/Users/nurl/ada/homework/FarMar/support/vendors.csv").each do |line|
all_vendors[line[0].to_i] = self.new(line[0].to_i,line[1],line[2].to_i,line[3].to_i)
end
return all_vendors
end

def self.find(id)
if all.has_key?(id)
return all[id]
else
raise ArgumentError.new("We do not have a vendor with that ID.")
end
end

def self.by_market(market_id)
all.delete_if do |k, v|
v.market_id != market_id
end
end

def market
all_markets = FarMar::Market.all
return all_markets[@id]
end

def products
all_products = FarMar::Product.all

all_products.delete_if do |k, v|
v.vendor_id != @id
end

return all_products
end

def sales
all_sales = FarMar::Sale.all

all_sales.delete_if do |k, v|
v.vendor_id != @id
end

return all_sales
end

def revenue
sales_amounts = sales.map do |k, v|
v.amount
end

sales_amounts.reduce(:+)
end

end
end
Loading