worlds-best-restaurants 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/bin/worlds-best-restaurants +5 -0
- data/config/environment.rb +7 -0
- data/lib/worlds_best_restaurants.rb +4 -0
- data/lib/worlds_best_restaurants/cli.rb +63 -0
- data/lib/worlds_best_restaurants/restaurant.rb +51 -0
- data/lib/worlds_best_restaurants/scraper.rb +20 -0
- metadata +120 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ae6d1c04f8f48e07f139f03f6d8e2df7ff685c3e
|
4
|
+
data.tar.gz: 044f099482e1b2e897a00446a0c41ec32971344d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6a2121d6fceb7e23753fd6883bb5e083824884bcb103d503be020c0b452198f4a1aeeed34a2fd388ea2fa3519b05fb06556968374dcedda89eecce1569dae58f
|
7
|
+
data.tar.gz: a0420aec4bc82124b095003270dc1c534ed923e78d627dfafc251d67a49cddf95fe02a684b7a69fcf82ff60116cd9d494fd22d4b90bd653e93036781c2de0361
|
@@ -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,120 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: worlds-best-restaurants
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.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
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.10'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.10'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: nokogiri
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: pry
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: Provides details on the San Pellegrino Worlds 50 Best restaurants
|
84
|
+
email: dannyd4315@gmail.com
|
85
|
+
executables:
|
86
|
+
- worlds-best-restaurants
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- bin/worlds-best-restaurants
|
91
|
+
- config/environment.rb
|
92
|
+
- lib/worlds_best_restaurants.rb
|
93
|
+
- lib/worlds_best_restaurants/cli.rb
|
94
|
+
- lib/worlds_best_restaurants/restaurant.rb
|
95
|
+
- lib/worlds_best_restaurants/scraper.rb
|
96
|
+
homepage: http://rubygems.org/gems/worlds-best-restaurants
|
97
|
+
licenses:
|
98
|
+
- MIT
|
99
|
+
metadata: {}
|
100
|
+
post_install_message:
|
101
|
+
rdoc_options: []
|
102
|
+
require_paths:
|
103
|
+
- lib
|
104
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - ">="
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: '0'
|
109
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
110
|
+
requirements:
|
111
|
+
- - ">="
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
version: '0'
|
114
|
+
requirements: []
|
115
|
+
rubyforge_project:
|
116
|
+
rubygems_version: 2.4.5.1
|
117
|
+
signing_key:
|
118
|
+
specification_version: 4
|
119
|
+
summary: Best Restaurants in the World
|
120
|
+
test_files: []
|