Contributions are welcome. Please first discuss with the owner of the repository via issue, email or any other method.
Please see code of conduct below.
def get_recipes_list | |
puts "\nHere's your curated recipes." | |
basic_recipes_arr = WeeklyMealPlanner::FoodAPI.get_recipes_list(search_hash) | |
WeeklyMealPlanner::Recipe.create_from_collection(basic_recipes_arr) | |
end | |
def get_recipe(input) | |
index = input.to_i - 1 | |
selected_recipe = WeeklyMealPlanner::Recipe.all[index] | |
add_recipe_details(selected_recipe) |
class WeeklyMealPlanner::Recipe | |
attr_accessor :id, :title | |
attr_reader :instruction, :ingredients, :servings | |
@@all = [] | |
def initialize(recipe_hash) | |
recipe_hash.each {|k, v| self.send(("#{k}="), v)} | |
@@all << self | |
end |
def update_servings(recipe) | |
puts "\nHow many servings of #{recipe.title} would you like to make?" | |
servings_input = gets.strip.to_i | |
unless servings_input > 0 | |
puts "Invalid input. Let's try again." | |
update_servings(recipe) | |
end | |
updated_ingredients = recipe.ingredients.map do |ingredient_hash| | |
ingredient_hash["amount"] *= (servings_input.to_f / recipe.servings.to_f) |
#11.0 -> 11; 0.25 -> 1/4; 1.47472 -> 1 1/2 | |
def parse_ingredient_amount(amount) | |
amount_arr = amount.to_s.split(".") | |
if amount_arr[1] == "0" | |
amount_arr[0] | |
else | |
amount = amount.to_r.rationalize(0.05) | |
amount_as_integer = amount.to_i | |
if (amount_as_integer != amount.to_f) && (amount_as_integer > 0) | |
fraction = amount - amount_as_integer |
post '/login' do | |
sanitize_input(params) | |
user = User.find_by(email: params[:email]) | |
if user && user.authenticate(params[:password]) | |
session[:user_id] = user.id | |
redirect to "/courses" | |
else | |
flash[:alerts] = ["Wrong email or password. Please try again."] | |
redirect to "/login" | |
end |
<% if !!flash[:alerts] %> | |
<div class="alert"> | |
<ul> | |
<% flash[:alerts].each do |alert| %> | |
<li><%= alert %></li> | |
<% end %> | |
</ul> | |
</div> | |
<% end %> |
ENV['SINATRA_ENV'] ||= "development" | |
require 'bundler/setup' | |
Bundler.require(:default, ENV['SINATRA_ENV']) | |
set :environment, ENV['SINATRA_ENV'].to_sym | |
database_config = { | |
:development => { | |
:adapter => 'sqlite3', |
class ApplicationController < Sinatra::Base | |
register Sinatra::ActiveRecordExtension | |
use Rack::Flash | |
configure do | |
enable :sessions | |
set :session_secret, "#{ENV['SESSION_SECRET']}" | |
set :public_folder, Proc.new { File.join(root, "public") } | |
set :views, 'app/views' | |
end |
def logged_in? | |
!!current_user | |
end | |
def current_user | |
@user ||= User.find_by_id(session[:user_id]) if session[:user_id] | |
end | |
def login_required | |
if !logged_in? |