Class: RestaurantWeekBoston::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/restaurant_week_boston/runner.rb

Overview

Used in the executable script, restaurant_week_boston.

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ Runner

Pass in ARGV.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/restaurant_week_boston/runner.rb', line 9

def initialize(argv)
  options = {}
  optparse = OptionParser.new do |opts|
    opts.banner = "Usage: #{$0} [options] restaurant1, restaurant2, ..."

    options[:meal] = :any
    opts.on('-m', '--meal MEAL', 'Only get restaurants that offer this meal (lunch/dinner/both/any)') do |m|
      options[:meal] = m
    end

    opts.on('-l', '--lunch RESTO1,RESTO2', 'Mark RESTAURANTS as good for lunch') do |lunches|
      options[:lunch] = lunches.split(',')
    end

    opts.on('-d', '--dinner RESTO1,RESTO2', 'Mark RESTAURANTS as good for dinner') do |dinners|
      options[:dinner] = dinners.split(',')
    end

    opts.on('-a', '--any RESTO1,RESTO2', 'Mark RESTAURANTS as good for any meal') do |any|
      options[:any] = any.split(',')
    end

    options[:neighborhood] = :all # NOT any!
    opts.on('-n', '--neighborhood HOOD',
            'Only get restaurants in this neighborhood (dorchester, back-bay, etc)') do |n|
      n = :all if n == 'any' # :any makes it choke
      options[:neighborhood] = n
    end

    opts.on('-h', '--help', 'Display this help') do
      puts opts
      return
    end
  end
  optparse.parse!(argv)
  @options = options
end

Instance Method Details

#runObject



47
48
49
50
51
52
53
# File 'lib/restaurant_week_boston/runner.rb', line 47

def run
  scraper = Scraper.new(:meal => @options[:meal],
                        :neighborhood => @options[:neighborhood])
  marker = Marker.new(scraper, @options)

  puts marker.all
end