Class: Grubber::Presenter

Inherits:
Object
  • Object
show all
Defined in:
lib/grubber/presenter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(restaurants) ⇒ Presenter

Returns a new instance of Presenter.



9
10
11
# File 'lib/grubber/presenter.rb', line 9

def initialize(restaurants)
  @restaurants = [*restaurants]
end

Instance Attribute Details

#restaurantsObject

Returns the value of attribute restaurants.



7
8
9
# File 'lib/grubber/presenter.rb', line 7

def restaurants
  @restaurants
end

Instance Method Details

#empty?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/grubber/presenter.rb', line 29

def empty?
  self.restaurants.empty?
end

#presentObject



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/grubber/presenter.rb', line 13

def present
  return nil if empty?

  restaurants.each do |r|
    puts "\n#{r.name} #{stars(r.rating)}"
    puts r.address
    puts "[#{r.category}] #{r.phone}"
    puts r.url
  end
  nil
end

#stars(rating) ⇒ Object



25
26
27
# File 'lib/grubber/presenter.rb', line 25

def stars(rating)
  ("" * rating) + ("" * (5 - rating))
end