Class: Arbitrage::Product

Inherits:
Object
  • Object
show all
Defined in:
lib/arbitrage/product.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeProduct

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_postObject

Returns the value of attribute cl_post.



2
3
4
# File 'lib/arbitrage/product.rb', line 2

def cl_post
  @cl_post
end

#nameObject

Returns the value of attribute name.



2
3
4
# File 'lib/arbitrage/product.rb', line 2

def name
  @name
end

#priceObject

Returns the value of attribute price.



2
3
4
# File 'lib/arbitrage/product.rb', line 2

def price
  @price
end

#queryObject

Returns the value of attribute query.



2
3
4
# File 'lib/arbitrage/product.rb', line 2

def query
  @query
end

#scraperObject

Returns the value of attribute scraper.



2
3
4
# File 'lib/arbitrage/product.rb', line 2

def scraper
  @scraper
end

#validatorObject

Returns the value of attribute validator.



2
3
4
# File 'lib/arbitrage/product.rb', line 2

def validator
  @validator
end

#zipcodeObject

Returns the value of attribute zipcode.



2
3
4
# File 'lib/arbitrage/product.rb', line 2

def zipcode
  @zipcode
end

Instance Method Details

#choose_productObject



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.buy_options.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_detailsObject



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_productObject



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_zipcodeObject



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_listObject



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_opportunityObject



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_stateObject



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