50-best-restaurants 0.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/bin/50-best-restaurants +5 -0
- data/config/environment.rb +7 -0
- data/lib/50_best_restaurants.rb +1 -0
- data/lib/50_best_restaurants/cli.rb +63 -0
- data/lib/50_best_restaurants/restaurant.rb +51 -0
- data/lib/50_best_restaurants/scraper.rb +20 -0
- metadata +50 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 032c4b49f2dd726ce316f623dcea4e38edd4772b
|
|
4
|
+
data.tar.gz: e45b963478329d37ef8794b0e8ed0a0d8f737b71
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 9eb145aa4681c6999437f7a5ab815e8a7102b195680927fcf995577b6686d5b539564e1fa20b2233f08bf6fa96bb152e3424477a2d18aebb443a84b5dfb0be2e
|
|
7
|
+
data.tar.gz: ae7a7ddc74c9806502938bf7ddee1deee82b9ad18696afe2fcef25cdf1e40277c0365766cca0970ad011e760086346fce2d0bbe8a7441676f1ea849e4fa05f59
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
require_relative '../config/environment'
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
class CLI
|
|
2
|
+
|
|
3
|
+
def call
|
|
4
|
+
Scraper.new.make_restaurants
|
|
5
|
+
puts "Welcome to the 50 Best Restaurants in the World"
|
|
6
|
+
start
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def start
|
|
10
|
+
puts ""
|
|
11
|
+
puts "What number restaurants would you like to see? 1-10, 11-20, 21-30, 31-40 or 41-50?"
|
|
12
|
+
input = gets.strip.to_i
|
|
13
|
+
|
|
14
|
+
print_restaurants(input)
|
|
15
|
+
|
|
16
|
+
puts ""
|
|
17
|
+
puts "What restaurant would you like more information on?"
|
|
18
|
+
input = gets.strip
|
|
19
|
+
|
|
20
|
+
restaurant = Restaurant.find(input.to_i)
|
|
21
|
+
|
|
22
|
+
print_restaurant(restaurant)
|
|
23
|
+
|
|
24
|
+
puts ""
|
|
25
|
+
puts "Would you like to see another restaurant? Enter Y or N"
|
|
26
|
+
|
|
27
|
+
input = gets.strip.downcase
|
|
28
|
+
if input == "y"
|
|
29
|
+
start
|
|
30
|
+
else
|
|
31
|
+
puts ""
|
|
32
|
+
puts "Thankyou! Have a great day!"
|
|
33
|
+
exit
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def print_restaurant(restaurant)
|
|
38
|
+
puts ""
|
|
39
|
+
puts "----------- #{restaurant.name} - #{restaurant.position} -----------"
|
|
40
|
+
puts ""
|
|
41
|
+
puts "Location: #{restaurant.location}"
|
|
42
|
+
puts "Head Chef: #{restaurant.head_chef}"
|
|
43
|
+
puts "Style of Food: #{restaurant.food_style}"
|
|
44
|
+
puts "Standout Dish: #{restaurant.best_dish}"
|
|
45
|
+
puts "Contact: #{restaurant.contact}"
|
|
46
|
+
puts "Website: #{restaurant.website_url}"
|
|
47
|
+
puts ""
|
|
48
|
+
puts "---------------Description--------------"
|
|
49
|
+
puts ""
|
|
50
|
+
puts "#{restaurant.description}"
|
|
51
|
+
puts ""
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def print_restaurants(from_number)
|
|
55
|
+
puts ""
|
|
56
|
+
puts "---------- Restaurants #{from_number} - #{from_number+9} ----------"
|
|
57
|
+
puts ""
|
|
58
|
+
Restaurant.all[from_number-1, 10].each.with_index(from_number) do |restaurant, index|
|
|
59
|
+
puts "#{index}. #{restaurant.name} - #{restaurant.location}"
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
end
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
class Restaurant
|
|
2
|
+
|
|
3
|
+
attr_accessor :name, :position, :location, :url, :head_chef, :website_url, :food_style, :best_dish, :contact, :description
|
|
4
|
+
|
|
5
|
+
@@all = []
|
|
6
|
+
|
|
7
|
+
def initialize(name=nil, url=nil, location=nil, position=nil)
|
|
8
|
+
@name = name
|
|
9
|
+
@url = url
|
|
10
|
+
@location = location
|
|
11
|
+
@position = position
|
|
12
|
+
@@all << self
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def self.all
|
|
16
|
+
@@all
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def self.find(id)
|
|
20
|
+
self.all[id-1]
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def best_dish
|
|
24
|
+
@best_dish = doc.xpath("//div[@class='c-4 nr nt']/ul[3]/li").text
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def food_style
|
|
28
|
+
@food_style = doc.xpath("//div[@class='c-4 nr nt']/ul[2]/li").text
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def contact
|
|
32
|
+
@contact = doc.xpath("//div[@class='c-4 nr nt']/ul[4]/li[1]").text.split("+").join(". Tel: +")
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def head_chef
|
|
36
|
+
@head_chef = doc.xpath("//div[@class='c-4 nr nt']/ul[1]/li").text.split(" (pictured)").join("")
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def website_url
|
|
40
|
+
@website_url = doc.xpath("//div[@class='c-4 nr nt']/ul[4]/li[2]/a").text
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def description
|
|
44
|
+
@description = doc.xpath("//div[@class='c-8 nl nt']/p[3]").text
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def doc
|
|
48
|
+
@doc ||= Nokogiri::HTML(open(self.url))
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
class Scraper
|
|
2
|
+
|
|
3
|
+
def get_page
|
|
4
|
+
Nokogiri::HTML(open("http://www.theworlds50best.com/list/1-50-winners"))
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
def scrape_restaurants_index
|
|
8
|
+
self.get_page.css("div#t1-50 li")
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def make_restaurants
|
|
12
|
+
scrape_restaurants_index.each do |r|
|
|
13
|
+
restaurant = Restaurant.new
|
|
14
|
+
restaurant.position = r.css(".position").text
|
|
15
|
+
restaurant.location = r.css("h3").text
|
|
16
|
+
restaurant.name = r.css("h2").text
|
|
17
|
+
restaurant.url = "http://www.theworlds50best.com" + r.css("a").attribute("href").text
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: 50-best-restaurants
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Danny Dawson
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2015-12-23 00:00:00.000000000 Z
|
|
12
|
+
dependencies: []
|
|
13
|
+
description: Provides details on the San Pellegrino Worlds 50 Best restaurants
|
|
14
|
+
email: dannyd4315@gmail.com
|
|
15
|
+
executables:
|
|
16
|
+
- 50-best-restaurants
|
|
17
|
+
extensions: []
|
|
18
|
+
extra_rdoc_files: []
|
|
19
|
+
files:
|
|
20
|
+
- bin/50-best-restaurants
|
|
21
|
+
- config/environment.rb
|
|
22
|
+
- lib/50_best_restaurants.rb
|
|
23
|
+
- lib/50_best_restaurants/cli.rb
|
|
24
|
+
- lib/50_best_restaurants/restaurant.rb
|
|
25
|
+
- lib/50_best_restaurants/scraper.rb
|
|
26
|
+
homepage: http://rubygems.org/gems/50-best-restaurants
|
|
27
|
+
licenses:
|
|
28
|
+
- MIT
|
|
29
|
+
metadata: {}
|
|
30
|
+
post_install_message:
|
|
31
|
+
rdoc_options: []
|
|
32
|
+
require_paths:
|
|
33
|
+
- lib
|
|
34
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
35
|
+
requirements:
|
|
36
|
+
- - ">="
|
|
37
|
+
- !ruby/object:Gem::Version
|
|
38
|
+
version: '0'
|
|
39
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
40
|
+
requirements:
|
|
41
|
+
- - ">="
|
|
42
|
+
- !ruby/object:Gem::Version
|
|
43
|
+
version: '0'
|
|
44
|
+
requirements: []
|
|
45
|
+
rubyforge_project:
|
|
46
|
+
rubygems_version: 2.4.5.1
|
|
47
|
+
signing_key:
|
|
48
|
+
specification_version: 4
|
|
49
|
+
summary: 50 Best Restaurants in the World
|
|
50
|
+
test_files: []
|