Class: ImHungry::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/im_hungry/cli.rb

Constant Summary collapse

NUM_PER_PAGE =
10
URL =
'http://data.sfgov.org/resource/bbb8-hzi6.json'.freeze

Class Method Summary collapse

Class Method Details

.fetch_im_hungryObject



14
15
16
# File 'lib/im_hungry/cli.rb', line 14

def self.fetch_im_hungry
  ImHungry::FetchJson.fetch(URL, ImHungry::FoodTruck)
end

.filter_food_trucks!(food_trucks) ⇒ Object



18
19
20
# File 'lib/im_hungry/cli.rb', line 18

def self.filter_food_trucks!(food_trucks)
  food_trucks.select!(&:currently_open?)
end


26
27
28
# File 'lib/im_hungry/cli.rb', line 26

def self.print(food_trucks)
  ImHungry::Paginate.new(food_trucks, NUM_PER_PAGE).print
end

.sort_food_trucks!(food_trucks) ⇒ Object



22
23
24
# File 'lib/im_hungry/cli.rb', line 22

def self.sort_food_trucks!(food_trucks)
  food_trucks.sort_by!(&:applicant)
end

.startObject



6
7
8
9
10
11
12
# File 'lib/im_hungry/cli.rb', line 6

def self.start
  food_trucks = fetch_im_hungry
  filter_food_trucks!(food_trucks)
  sort_food_trucks!(food_trucks)
  print(food_trucks)
  exit
end