Class: WorldsBestRestaurants::Restaurant

Inherits:
Object
  • Object
show all
Defined in:
lib/worlds_best_restaurants/restaurant.rb

Constant Summary collapse

@@all =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name = nil, url = nil, location = nil, position = nil) ⇒ Restaurant

Returns a new instance of Restaurant.



16
17
18
19
20
21
22
# File 'lib/worlds_best_restaurants/restaurant.rb', line 16

def initialize(name=nil, url=nil, location=nil, position=nil)
  @name = name
  @url = url
  @location = location
  @position = position
  @@all << self
end

Instance Attribute Details

#best_dishObject

Returns the value of attribute best_dish.



3
4
5
# File 'lib/worlds_best_restaurants/restaurant.rb', line 3

def best_dish
  @best_dish
end

#contactObject

Returns the value of attribute contact.



3
4
5
# File 'lib/worlds_best_restaurants/restaurant.rb', line 3

def contact
  @contact
end

#descriptionObject

Returns the value of attribute description.



3
4
5
# File 'lib/worlds_best_restaurants/restaurant.rb', line 3

def description
  @description
end

#food_styleObject

Returns the value of attribute food_style.



3
4
5
# File 'lib/worlds_best_restaurants/restaurant.rb', line 3

def food_style
  @food_style
end

#head_chefObject

Returns the value of attribute head_chef.



3
4
5
# File 'lib/worlds_best_restaurants/restaurant.rb', line 3

def head_chef
  @head_chef
end

#locationObject

Returns the value of attribute location.



3
4
5
# File 'lib/worlds_best_restaurants/restaurant.rb', line 3

def location
  @location
end

#nameObject

Returns the value of attribute name.



3
4
5
# File 'lib/worlds_best_restaurants/restaurant.rb', line 3

def name
  @name
end

#positionObject

Returns the value of attribute position.



3
4
5
# File 'lib/worlds_best_restaurants/restaurant.rb', line 3

def position
  @position
end

#urlObject

Returns the value of attribute url.



3
4
5
# File 'lib/worlds_best_restaurants/restaurant.rb', line 3

def url
  @url
end

#website_urlObject

Returns the value of attribute website_url.



3
4
5
# File 'lib/worlds_best_restaurants/restaurant.rb', line 3

def website_url
  @website_url
end

Class Method Details

.allObject



24
25
26
# File 'lib/worlds_best_restaurants/restaurant.rb', line 24

def self.all
  @@all
end

.find(id) ⇒ Object



28
29
30
# File 'lib/worlds_best_restaurants/restaurant.rb', line 28

def self.find(id)
  self.all[id-1]
end

.new_from_index_page(r) ⇒ Object



7
8
9
10
11
12
13
14
# File 'lib/worlds_best_restaurants/restaurant.rb', line 7

def self.new_from_index_page(r)
  self.new(
    r.css("h2").text, 
    "http://www.theworlds50best.com#{r.css("a").attribute("href").text}",
    r.css("h3").text,
    r.css(".position").text
    )
end

Instance Method Details

#docObject



56
57
58
# File 'lib/worlds_best_restaurants/restaurant.rb', line 56

def doc 
  @doc ||= Nokogiri::HTML(open(self.url))
end