Class: Eatable::Scraper
- Inherits:
-
Object
- Object
- Eatable::Scraper
- Defined in:
- lib/eatable/scraper.rb
Constant Summary collapse
- NUTS =
/nut|almond|cashew|macadamia|pecan|pigñolia|pistachio|praline|pesto|filbert/- SHELL_FISH =
/shrimp|clam|mussel|lobster|crab|prawn/
Class Method Summary collapse
- .city_url ⇒ Object
- .filter_menus(menus_array) ⇒ Object
- .full_neighborhood_url ⇒ Object
- .full_neighborhood_url=(neighborhood_url) ⇒ Object
- .neighborhood_scrape(city_name) ⇒ Object
- .restaurant_scrape(neighborhood_url) ⇒ Object
Class Method Details
.city_url ⇒ Object
62 63 64 |
# File 'lib/eatable/scraper.rb', line 62 def self.city_url @@city_url end |
.filter_menus(menus_array) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/eatable/scraper.rb', line 41 def self.() valid_restaurants = [] [0..10].each do || = Nokogiri::HTML(open()) = (.css('div #restaurant-menu').text.gsub(/\r\n/, "").gsub(/\u00A0/, "")).downcase # --------------- Adjust tolerence level for number of search terms ----------------------------- if (.scan(NUTS).length <= 2) && (.scan(SHELL_FISH).length <= 2) && (.length > 20) restaurant = { "name" => .css('div h1.title1respage').text, "address" => "#{.css('span.addr').text}", "phone" => .css('li.phonenew').text.gsub(/[\\rn\s]/, "") } valid_restaurants << restaurant end end valid_restaurants end |
.full_neighborhood_url ⇒ Object
74 75 76 |
# File 'lib/eatable/scraper.rb', line 74 def self.full_neighborhood_url @@full_neighborhood_url end |
.full_neighborhood_url=(neighborhood_url) ⇒ Object
66 67 68 69 70 71 72 |
# File 'lib/eatable/scraper.rb', line 66 def self.full_neighborhood_url=(neighborhood_url) if @@city_url == "http://www.menupages.com" @@full_neighborhood_url = neighborhood_url else @@full_neighborhood_url = @@city_url + neighborhood_url end end |
.neighborhood_scrape(city_name) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/eatable/scraper.rb', line 11 def self.neighborhood_scrape(city_name) neighborhoods = {} @@city_url = 'http://' + city_name + '.menupages.com' citypg = Nokogiri::HTML(open(@@city_url)) citypg.css('#image-map area').each do |a| neighborhood_url = a.attr('href') name = a.attr('alt') neighborhoods[name] = neighborhood_url end neighborhoods end |
.restaurant_scrape(neighborhood_url) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/eatable/scraper.rb', line 25 def self.restaurant_scrape(neighborhood_url) = [] self.full_neighborhood_url=(neighborhood_url) neighb_pg = Nokogiri::HTML(open(self.full_neighborhood_url)) rest_table = neighb_pg.css('tbody tr td a') rest_table.each do|listing| << listing.attr('href') unless ((listing.attr('href')).include?('grubhub') || (listing.attr('href')).include?('seamless')) end .map! {|link| self.city_url + link + "menu"} self.() end |