Class: RestaurantWeekBoston::Restaurant

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/restaurant_week_boston/restaurant.rb

Overview

A Restaurant has the following properties:

  • name (“224 Boston Street”)

  • short-name (“224-boston-street”, used internally by RWB site)

  • meals: %wdinner, %wlunch, %wdinner

  • neighborhood: “back-bay”, etc

  • phone: “617-555-1234”

  • menu: use menu_link_for(“lunch” || “dinner”)

  • map_link: a link to the RWB map page for that Restaurant

Instance Method Summary collapse

Constructor Details

#initialize(entry) ⇒ Restaurant

entry is a Nokogiri::XML::Node from the RWB web site.



14
15
16
# File 'lib/restaurant_week_boston/restaurant.rb', line 14

def initialize(entry)
  @entry = entry
end

Instance Method Details

#<=>(other) ⇒ Object

Compares this Restaurant’s name to other‘s name, and returns -1, 0, 1 as appropriate.



20
21
22
# File 'lib/restaurant_week_boston/restaurant.rb', line 20

def <=>(other)
  name <=> other.name
end

#inspectObject

Returns “<Restaurant: #restaurant-name>”



41
42
43
# File 'lib/restaurant_week_boston/restaurant.rb', line 41

def inspect
  "<Restaurant: #{name}>"
end

#nameObject

Return the full name of this Restaurant, e.g. “224 Boston Street”.



46
47
48
# File 'lib/restaurant_week_boston/restaurant.rb', line 46

def name
  @name ||= @entry.css('h4 a[href^="/restaurant"]').text.strip
end

#to_sObject

Generate a pretty representation of the Restaurant.



25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/restaurant_week_boston/restaurant.rb', line 25

def to_s
  s = <<-EOS
Name: #{name}
Meals: #{meals.map(&:capitalize).join(', ')}
Neighborhood: #{neighborhood}
Phone: #{phone}
EOS
  @meals.each do |meal|
    s += "#{meal.capitalize} Menu: #{menu_link_for(meal)}"
    s += "\n"
  end
  s += "Map: #{map_link}"
  s
end