worlds-best-restaurants 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 789a4a7f63b87b85d0beedcc847b428acf33fc3c
4
- data.tar.gz: ee83b3feb2c7c60e61857e1a35e6d3a07aba1ec3
3
+ metadata.gz: 0e93565066b8011d2c2ec489594eefbe69d61808
4
+ data.tar.gz: 4c7e26600dde9dc64bac269fb14977f6e1710564
5
5
  SHA512:
6
- metadata.gz: 22949132e2ca37920e97dfeb173385fdb028af3a45cfb5fdae97744fd42f3dc69637bb6ccff4bbd66acbb7ccd1d76de9a4b9fd0cb7ee88bb2a2bc99f5665f7f9
7
- data.tar.gz: 4a40db61c9200460d01598f9c4e683006f39c887ebff433a02ceb4ca4ac58cc59f3b71b34926d1d8f58fde8ee3d11d54a7051714583fa08c7b02699b237bf2d0
6
+ metadata.gz: 1fd0dc42e169b1bb7cc77bdc4a82ec3c0601bce3f236049bc83fa91f9503cb1f049f718eb9c7c21e07b45db01ab58e9fc2fcd99ed640fab4b3e6dff557c42484
7
+ data.tar.gz: 0dadd8365620474a186cd4cac595abc3813e475e9406cda080881f917d0f056ee5f6ffb1b82d67b1cba0b0c99c715355839b7bc89efead375bbd121899e3f69b
@@ -2,4 +2,4 @@
2
2
 
3
3
  require_relative '../lib/worlds_best_restaurants'
4
4
 
5
- CLI.new.call
5
+ WorldsBestRestaurants::CLI.new.call
@@ -1,4 +1,4 @@
1
- require_relative '../config/environment'
2
-
3
1
  module WorldsBestRestaurants
4
2
  end
3
+
4
+ require_relative '../config/environment'
@@ -1,7 +1,7 @@
1
- class CLI
1
+ class WorldsBestRestaurants::CLI
2
2
 
3
3
  def call
4
- Scraper.new.make_restaurants
4
+ WorldsBestRestaurants::Scraper.new.make_restaurants
5
5
  puts "Welcome to the 50 Best Restaurants in the World"
6
6
  start
7
7
  end
@@ -17,7 +17,7 @@ class CLI
17
17
  puts "What restaurant would you like more information on?"
18
18
  input = gets.strip
19
19
 
20
- restaurant = Restaurant.find(input.to_i)
20
+ restaurant = WorldsBestRestaurants::Restaurant.find(input.to_i)
21
21
 
22
22
  print_restaurant(restaurant)
23
23
 
@@ -55,7 +55,7 @@ class CLI
55
55
  puts ""
56
56
  puts "---------- Restaurants #{from_number} - #{from_number+9} ----------"
57
57
  puts ""
58
- Restaurant.all[from_number-1, 10].each.with_index(from_number) do |restaurant, index|
58
+ WorldsBestRestaurants::Restaurant.all[from_number-1, 10].each.with_index(from_number) do |restaurant, index|
59
59
  puts "#{index}. #{restaurant.name} - #{restaurant.location}"
60
60
  end
61
61
  end
@@ -1,9 +1,18 @@
1
- class Restaurant
1
+ class WorldsBestRestaurants::Restaurant
2
2
 
3
3
  attr_accessor :name, :position, :location, :url, :head_chef, :website_url, :food_style, :best_dish, :contact, :description
4
4
 
5
5
  @@all = []
6
6
 
7
+ def self.new_from_index_page(r)
8
+ self.new(
9
+ r.css("h2").text,
10
+ "http://www.theworlds50best.com#{r.css("a").attribute("href").text}",
11
+ r.css("h3").text,
12
+ r.css(".position").text
13
+ )
14
+ end
15
+
7
16
  def initialize(name=nil, url=nil, location=nil, position=nil)
8
17
  @name = name
9
18
  @url = url
@@ -21,27 +30,27 @@ class Restaurant
21
30
  end
22
31
 
23
32
  def best_dish
24
- @best_dish = doc.xpath("//div[@class='c-4 nr nt']/ul[3]/li").text
33
+ @best_dish ||= doc.xpath("//div[@class='c-4 nr nt']/ul[3]/li").text
25
34
  end
26
35
 
27
36
  def food_style
28
- @food_style = doc.xpath("//div[@class='c-4 nr nt']/ul[2]/li").text
37
+ @food_style ||= doc.xpath("//div[@class='c-4 nr nt']/ul[2]/li").text
29
38
  end
30
39
 
31
40
  def contact
32
- @contact = doc.xpath("//div[@class='c-4 nr nt']/ul[4]/li[1]").text.split("+").join(". Tel: +")
41
+ @contact ||= doc.xpath("//div[@class='c-4 nr nt']/ul[4]/li[1]").text.split("+").join(". Tel: +")
33
42
  end
34
43
 
35
44
  def head_chef
36
- @head_chef = doc.xpath("//div[@class='c-4 nr nt']/ul[1]/li").text.split(" (pictured)").join("")
45
+ @head_chef ||= doc.xpath("//div[@class='c-4 nr nt']/ul[1]/li").text.split(" (pictured)").join("")
37
46
  end
38
47
 
39
48
  def website_url
40
- @website_url = doc.xpath("//div[@class='c-4 nr nt']/ul[4]/li[2]/a").text
49
+ @website_url ||= doc.xpath("//div[@class='c-4 nr nt']/ul[4]/li[2]/a").text
41
50
  end
42
51
 
43
52
  def description
44
- @description = doc.xpath("//div[@class='c-8 nl nt']/p[3]").text
53
+ @description ||= doc.xpath("//div[@class='c-8 nl nt']/p[3]").text
45
54
  end
46
55
 
47
56
  def doc
@@ -1,4 +1,4 @@
1
- class Scraper
1
+ class WorldsBestRestaurants::Scraper
2
2
 
3
3
  def get_page
4
4
  Nokogiri::HTML(open("http://www.theworlds50best.com/list/1-50-winners"))
@@ -10,11 +10,7 @@ class Scraper
10
10
 
11
11
  def make_restaurants
12
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
13
+ WorldsBestRestaurants::Restaurant.new_from_index_page(r)
18
14
  end
19
15
  end
20
16
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: worlds-best-restaurants
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Danny Dawson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-12-23 00:00:00.000000000 Z
11
+ date: 2016-01-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler