Class: BobaFinder::Finder

Inherits:
Object
  • Object
show all
Defined in:
lib/boba_finder_CLI/finder.rb

Class Method Summary collapse

Class Method Details

.scrape_yelpObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/boba_finder_CLI/finder.rb', line 20

def self.scrape_yelp
  self.user_zip
  doc = Nokogiri::HTML(open(@link, "User-Agent" => "JCS", "From" => "[email protected]"))
  doc.xpath("//script").remove

  doc.search("li.regular-search-result").map do |spot|
    name = spot.css("a.biz-name span").text
    stars = spot.css("div.i-stars").attr("title").value
    city = spot.css("span.biz-city").children.text if spot.css("span.biz-city")
    neighborhood = spot.css("span.neighborhood-str-list").children.text.strip if spot.css("span.neighborhood-str-list")
    address = spot.css("address").children.text.strip
    telephone = spot.css("span.biz-phone").children.text.strip
    BobaFinder::Boba.new(name, stars, city, neighborhood, address, telephone)
  end
end

.user_zipObject



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/boba_finder_CLI/finder.rb', line 3

def self.user_zip
  puts "What is your ZIP code?"
  input = gets.strip
  if input.size != 5
    puts "Invalid number! Please put a proper ZIP code.".colorize(:red)
    sleep 1
    puts "----------------------".colorize(:green)
    self.user_zip
  else
    @link = "https://www.yelp.com/search?find_desc=boba&find_loc=#{input}"
    sleep 1
    puts "Here's a list of places near you:"
    puts "\n"
    sleep 2
  end
end