class FastFoodNutrition::Welcome

Public Instance Methods

bye() click to toggle source
# File lib/Fast_Food_Nutrition/cli.rb, line 57
def bye
  puts "\nThank You for using the Fast Food Nutrition Finder"
end
continue?() click to toggle source
# File lib/Fast_Food_Nutrition/cli.rb, line 50
def continue?
  input = ""
  puts "\nWould you like to continue to find more items? (y/n)"
  input = gets.strip.downcase until input == "y" || input == "n"
  input == "y" ? list_restaurants : bye
end
get_nutrition(restaurant, cat_picked, item_picked) click to toggle source
# File lib/Fast_Food_Nutrition/cli.rb, line 41
def get_nutrition(restaurant, cat_picked, item_picked)
  restaurant.categories[cat_picked].items[item_picked].nutrition = FastFoodNutrition::Scraper.new.scrape_nutrition_info(restaurant, cat_picked, item_picked) if !restaurant.categories[cat_picked].items[item_picked].nutrition
  puts "\nHere is the nutrition information for #{restaurant.categories[cat_picked].items[item_picked].name}:"
  restaurant.categories[cat_picked].items[item_picked].nutrition.each do |item|
    puts "  #{item[0]}: #{item[1]}"
  end
  continue?
end
intro() click to toggle source
# File lib/Fast_Food_Nutrition/cli.rb, line 3
def intro
  puts "Welcome To The Fast Food Nutrition Finder"
  list_restaurants
end
list_restaurants() click to toggle source
# File lib/Fast_Food_Nutrition/cli.rb, line 8
def list_restaurants
  selection = 0
  puts "\nPlease select a Restaurant by number:"
  FastFoodNutrition::Scraper.new.scrape_site_for_restaurants("http://www.nutrition-charts.com/") if FastFoodNutrition::Restaurant.all.size == 0
  FastFoodNutrition::Restaurant.all.each_with_index {|restaurant, i| puts "#{i + 1}: #{restaurant.name}"}
  # consider #between?
  selection = gets.strip.to_i until selection.between?(1, FastFoodNutrition::Restaurant.all.size)
  puts "\nYou selected #{FastFoodNutrition::Restaurant.all[selection - 1].name}"
  select_category(FastFoodNutrition::Restaurant.all[selection - 1])
end
select_category(restaurant) click to toggle source
# File lib/Fast_Food_Nutrition/cli.rb, line 19
def select_category(restaurant)
  restaurant.categories = FastFoodNutrition::Scraper.new.scrape_restaurant_categories(restaurant) if !restaurant.categories
  selection = 0
  puts "\nPlease select a Category of Menu Items:"
  restaurant.categories.each_with_index {|category, i| puts "#{i + 1}: #{category.name}"}
  selection = gets.strip.to_i until selection.between?(1, restaurant.categories.size)
  puts "\nYou selected #{restaurant.categories[selection - 1].name}"
  select_item(restaurant, selection - 1)
end
select_item(restaurant, cat_picked) click to toggle source
# File lib/Fast_Food_Nutrition/cli.rb, line 29
def select_item(restaurant, cat_picked)
  restaurant.categories[cat_picked].items = FastFoodNutrition::Scraper.new.scrape_category_items(restaurant, cat_picked) if !restaurant.categories[cat_picked].items
  selection = 0
  puts "\nPlease select an item:"
  restaurant.categories[cat_picked].items.each_with_index do |item, i|
    puts "#{i + 1}: #{item.name}"
  end
  selection = gets.strip.to_i until selection.between?(1, restaurant.categories[cat_picked].items.size)
  puts "\nYou selected #{restaurant.categories[cat_picked].items[selection - 1].name}"
  get_nutrition(restaurant, cat_picked, selection - 1)
end