In this assignment we will be creating an application to look up Farmers Markets and their related vendors, products, and sales. We will use CSV files as our database.
- Pair up!
- The individual closest to the center of the room will fork the repo: https://github.com/Ada-Developers-Academy/far_mar_finder
- Add the second individual as a collaborator
- Both individuals will clone the repo
git clone [YOUR FORKED REPO URL]
- Both individuals cd into the dir created
cd far_mar_finder
- Both individuals install rspec (in Terminal.app)
gem install rspec
Start building! (but read on for more info)
There are several CSV data files:
/support/markets.csv
/support/products.csv
/support/vendors.csv
/support/sales.csv
Build classes to query the CSV data including objects and methods listed below. Before going too deeply into the methods listed, start by building a system to read the csv files and turn each row of data into an instance of the corresponding ruby class.
To manage our data classes we will use a file named /lib/far_mar_finder.rb
require 'csv'
require 'time'
require_relative 'market'
# ... require all needed classes
class FarMarFinder
# Your Code Here
end
You will start by creating methods for FarMarFinder to return the class of each of the supporting classes
finder = FarMarFinder.new
finder.markets
#=> Market
finder.vendors
#=> Vendor
finder.products
#=> Product
finder.sales
#=> Sale
We will build class methods on the returned class Object
finder = FarMarFinder.new
finder.markets.all
# => [...] Returns all instances of the Market class
See below for full description of methods to create.
For each of the data classes build the following methods:
self.all
- returns all rows of the CSV file as objectsself.find(id)
- returns the row where the ID field matches the argumentself.find_by_x(match)
- where X is an attribute, returns a single instance whose X attribute case-insensitive attribute matches the match parameter. For instance, Vendor.find_by_name("windler inc") could find a Vendor with the name attribute "windler inc" or "Windler Inc".self.find_all_by_x(match)
- works just likefind_by_x
but returns a collection containing all possible matches. For exampleMarket.find_by_state("WA")
could return all of the Market object with"WA"
in their state field.
Additional Market Methods
vendors
- returns a collection ofVendor
instances that are associated with the market by the market_id field.
Additional Vendor Methods
market
- returns theMarket
instance that is associated with this vendor using theVendor
market_id
fieldproducts
- returns a collection ofProduct
instances that are associated with market by theProduct
vendor_id
field.sales
- returns a collection ofSale
instances that are associated with market by thevendor_id
field.revenue
- returns the the sum of all of the vendor's sales (in cents)
Additional Product Methods
vendor
- returns theVendor
instance that is associated with this vendor using theProduct
vendor_id
fieldsales
- returns a collection ofSale
instances that are associated with market using theSale
product_id
field.number_of_sales
- returns the number of times this product has been sold.
Additional Sale Methods
vendor
- returns theVendor
instance that is associated with this sale using theSale
vendor_id
fieldproduct
- returns theProduct
instance that is associated with this sale using theSale
product_id
fieldself.between(beginning_time, end_time)
- returns a collection of Sale objects where the purchase time is between the two times given as arguments
To run our test suite use:
rspec -c
Our test suite will run tests to ensure that some of our required methods are implemented correctly.
Note: It will be best to create the basic file for the four supporting classes before running our tests
class Market
end
and requiring them in /lib/far_mar_finder.rb
.
You will be evaluated on:
- Running
rspec
from Terminal with no failures - Demonstrating, in IRB, a few of the methods listed above (asked at random).
- Code quality (is your code organized and logical)
- Extra credit for additional methods to add neat functionality
- Extra credit for writing additional specs
Our supporting classes will also live in the /lib
dir.
The Market data, in order in the CSV, consists of:
- ID
- Name
- Address
- City
- County
- State
- Zip
An individual market has many vendors
The Vendor data, in order in the CSV, consists of:
- ID
- Name
- No. of Employees
- Market_id
Each vendor belongs to a market, the market_id field relates to the Market ID field. Each vendor has many products they sell.
The Product data, in order in the CSV, consists of:
- ID
- Name
- Vendor_id
Each product belongs to a vendor, the vendor_id field relates to the Vendor ID field.
The Sale data, in order in the CSV, consists of:
- ID
- Amount (in cents)
- Purchase Time
- Vendor_id
- Product_id
Each sale belongs to a vendor AND an product, the vendor_id and product_id fields relates to the Vendor and Product ID fields