Class: Arbitrage::Product
- Inherits:
-
Object
- Object
- Arbitrage::Product
- Defined in:
- lib/arbitrage/product.rb
Instance Attribute Summary collapse
-
#cl_post ⇒ Object
Returns the value of attribute cl_post.
-
#name ⇒ Object
Returns the value of attribute name.
-
#price ⇒ Object
Returns the value of attribute price.
-
#query ⇒ Object
Returns the value of attribute query.
-
#scraper ⇒ Object
Returns the value of attribute scraper.
-
#validator ⇒ Object
Returns the value of attribute validator.
-
#zipcode ⇒ Object
Returns the value of attribute zipcode.
Instance Method Summary collapse
- #choose_product ⇒ Object
- #display_product_details ⇒ Object
- #get_product ⇒ Object
- #get_zipcode ⇒ Object
-
#initialize ⇒ Product
constructor
A new instance of Product.
- #product_list ⇒ Object
- #remove_0_from_zip(zipcode) ⇒ Object
- #show_arbitrage_opportunity ⇒ Object
- #user_city_state ⇒ Object
Constructor Details
#initialize ⇒ Product
Returns a new instance of Product.
4 5 6 7 8 |
# File 'lib/arbitrage/product.rb', line 4 def initialize self.scraper = Arbitrage::Scraper.new self.scraper.product = self self.validator = Arbitrage::InputValidator.new end |
Instance Attribute Details
#cl_post ⇒ Object
Returns the value of attribute cl_post.
2 3 4 |
# File 'lib/arbitrage/product.rb', line 2 def cl_post @cl_post end |
#name ⇒ Object
Returns the value of attribute name.
2 3 4 |
# File 'lib/arbitrage/product.rb', line 2 def name @name end |
#price ⇒ Object
Returns the value of attribute price.
2 3 4 |
# File 'lib/arbitrage/product.rb', line 2 def price @price end |
#query ⇒ Object
Returns the value of attribute query.
2 3 4 |
# File 'lib/arbitrage/product.rb', line 2 def query @query end |
#scraper ⇒ Object
Returns the value of attribute scraper.
2 3 4 |
# File 'lib/arbitrage/product.rb', line 2 def scraper @scraper end |
#validator ⇒ Object
Returns the value of attribute validator.
2 3 4 |
# File 'lib/arbitrage/product.rb', line 2 def validator @validator end |
#zipcode ⇒ Object
Returns the value of attribute zipcode.
2 3 4 |
# File 'lib/arbitrage/product.rb', line 2 def zipcode @zipcode end |
Instance Method Details
#choose_product ⇒ Object
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/arbitrage/product.rb', line 20 def choose_product choice = gets.chomp self.scraper..each do |number, hash| if choice == number self.name = hash[:name] self.price = hash[:price] self.cl_post = hash[:url] end end end |
#display_product_details ⇒ Object
31 32 33 34 35 |
# File 'lib/arbitrage/product.rb', line 31 def display_product_details puts "->Product Title- #{self.name}" puts "->Buying Price- #{self.price}" puts "->Where to Buy- #{self.cl_post}" end |
#get_product ⇒ Object
10 11 12 13 14 15 16 17 18 |
# File 'lib/arbitrage/product.rb', line 10 def get_product puts "Enter the product you intend to sell" self.name = gets.chomp product_list puts "------------------------------------------------------" puts "Enter the number of the product you would like to research from the list above" choose_product show_arbitrage_opportunity end |
#get_zipcode ⇒ Object
42 43 44 45 46 47 48 49 |
# File 'lib/arbitrage/product.rb', line 42 def get_zipcode zipcode = gets.chomp if !(self.validator.zipcode_valid?(zipcode)) puts "Invalid zipcode, please enter zipcode" get_zipcode end remove_0_from_zip(zipcode) end |
#product_list ⇒ Object
37 38 39 40 |
# File 'lib/arbitrage/product.rb', line 37 def product_list self.scraper.create_index_url self.scraper.create_product_list end |
#remove_0_from_zip(zipcode) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/arbitrage/product.rb', line 55 def remove_0_from_zip(zipcode) zipcode = zipcode.split("") if zipcode.first == "0" zipcode.delete_at(0) zipcode= zipcode.join self.zipcode = zipcode else zipcode= zipcode.join self.zipcode = zipcode end end |
#show_arbitrage_opportunity ⇒ Object
51 52 53 |
# File 'lib/arbitrage/product.rb', line 51 def show_arbitrage_opportunity nearby_cls = Arbitrage::NearbyCraigslists.new(self,self.scraper) end |
#user_city_state ⇒ Object
67 68 69 70 |
# File 'lib/arbitrage/product.rb', line 67 def user_city_state location = ZipCodes.identify(self.zipcode) location = "#{location[:city]},#{location[:state_code]}" end |