dietologist 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/bin/dietologist +6 -0
- data/config/environment.rb +6 -0
- data/lib/cli.rb +25 -0
- data/lib/concerns.rb +70 -0
- data/lib/dietologist.rb +6 -0
- data/lib/meal-plan.rb +35 -0
- data/lib/processor.rb +68 -0
- data/lib/summarize-recipe.rb +33 -0
- metadata +122 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 7afeb254413b124b595ae97b416173fdcdfb2b12ed7ee0dfe584deccd810d34e
|
4
|
+
data.tar.gz: 296d05c8eeca0a3f1664f4201a6597e047a436c6cd03831d1d305e4ac15dfea5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: fe10a4efd54fd7b3da62a314137c6cffcf48c521b04bde9116b61c21a51d327222fbe9ceea8585756cc0efad626628be36d2eef543a32c88ce627dff488525fe
|
7
|
+
data.tar.gz: 364f3bb64fd43a3266e48c3c63e0a8ffc0f7a1e571e814cd2be9bf271b6e7d355f8ea20e229ae516f52b5cf32f300adb322fb0a8445d7c4bd76c53006d3702be
|
data/bin/dietologist
ADDED
data/lib/cli.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require_relative './concerns.rb'
|
2
|
+
|
3
|
+
class Dietologist::CLI
|
4
|
+
|
5
|
+
attr_reader :meal_hash
|
6
|
+
|
7
|
+
include Concerns::InstanceMethods
|
8
|
+
extend Concerns::ClassMethods
|
9
|
+
|
10
|
+
def initialize
|
11
|
+
@processor = Processor.new
|
12
|
+
end
|
13
|
+
|
14
|
+
def start
|
15
|
+
puts " ♦♦♦♦♦♦ Welcome to the Dietologist ♦♦♦♦♦♦ "
|
16
|
+
puts " ♦♦♦ We're going to create a customized diet plan for you ♦♦♦ "
|
17
|
+
@processor.bond
|
18
|
+
@data = Processor::DATA
|
19
|
+
@meal_plan = MealPlan.new(@data[:time_frame], @data[:target_calories], @data[:diet], @data[:exclude])
|
20
|
+
@meal_hash = @meal_plan.meal_getter
|
21
|
+
meals_info_day(@meal_hash) if @data[:time_frame] == 'day'
|
22
|
+
meals_info_week(@meal_hash) if @data[:time_frame] == 'week'
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
data/lib/concerns.rb
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
module Concerns
|
2
|
+
|
3
|
+
module InstanceMethods
|
4
|
+
|
5
|
+
def meals_info_day(hash)
|
6
|
+
puts "♦♦ Here is a customized menu plan for you based on the information provided ♦♦"
|
7
|
+
puts "♦♦♦ calories: #{hash["nutrients"]["calories"]}, protein: #{hash["nutrients"]["protein"]}, fat: #{hash["nutrients"]["fat"]}, carbohydrates: #{hash["nutrients"]['carbohydrates']} ♦♦♦ "
|
8
|
+
puts " ♦♦ Including #{hash['meals'].size} recipes: ♦♦ "
|
9
|
+
meal_position = 1
|
10
|
+
hash['meals'].each do |meal|
|
11
|
+
puts "♦♦ #{meal_position}. #{meal["title"]} | #{meal["servings"]} serving(s) with cooking time about #{meal['readyInMinutes']} minutes. ♦♦"
|
12
|
+
puts ""
|
13
|
+
meal_position += 1
|
14
|
+
end
|
15
|
+
puts "♦♦♦ Which recipe you would like to find out more about? enter a number [1-#{hash['meals'].size}] or type in 'exit' ♦♦♦"
|
16
|
+
choose_recipe = gets.chomp
|
17
|
+
if choose_recipe != 'exit'
|
18
|
+
meal_index = choose_recipe.to_i - 1
|
19
|
+
id = hash['meals'][meal_index]['id']
|
20
|
+
meal_details(id)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def meals_info_week(hash)
|
25
|
+
puts "♦♦♦ We've created a diet plan for you for entire week that includes #{hash['items'].size} recipes ♦♦♦"
|
26
|
+
puts ""
|
27
|
+
counter = 1
|
28
|
+
hash['items'].each do |day|
|
29
|
+
values = day['value'].split(/[:,"]/)
|
30
|
+
puts "♦♦ [#{counter}.] Day #{day['day']}. #{values[14]} ♦♦"
|
31
|
+
counter += 1
|
32
|
+
end
|
33
|
+
puts "♦♦♦ Which recipe you would like to find out more about? enter a number [1-#{hash['items'].size}] or type in 'exit' ♦♦♦"
|
34
|
+
choose_recipe = gets.chomp
|
35
|
+
if choose_recipe != 'exit'
|
36
|
+
meal_index = choose_recipe.to_i - 1
|
37
|
+
id_splitter = hash['items'][meal_index]['value'].split(/[:,"]/)
|
38
|
+
id = id_splitter[3]
|
39
|
+
meal_details(id)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def meal_details(id)
|
44
|
+
dish = SummarizeRecipe.new(id)
|
45
|
+
recipe_info_hash = dish.recipe_getter
|
46
|
+
puts "♦♦♦♦♦♦ #{recipe_info_hash['title']} ♦♦♦♦♦♦"
|
47
|
+
puts ""
|
48
|
+
puts recipe_info_hash['summary']
|
49
|
+
puts ""
|
50
|
+
puts "♦♦♦ Press 1 to go back, or press 2 to exit ♦♦♦"
|
51
|
+
option = gets.chomp
|
52
|
+
if Processor::DATA[:time_frame] == 'day'
|
53
|
+
meals_info_day(self.meal_hash) if option == '1'
|
54
|
+
end
|
55
|
+
if Processor::DATA[:time_frame] == 'week'
|
56
|
+
meals_info_week(self.meal_hash) if option == '1'
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
|
62
|
+
module ClassMethods
|
63
|
+
|
64
|
+
def all
|
65
|
+
@@all
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
data/lib/dietologist.rb
ADDED
data/lib/meal-plan.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
class MealPlan
|
2
|
+
|
3
|
+
attr_reader :meal_hash
|
4
|
+
|
5
|
+
@@all = []
|
6
|
+
|
7
|
+
def initialize(time_frame, target_calories, diet, exclude)
|
8
|
+
@time_frame = time_frame
|
9
|
+
@target_calories = target_calories
|
10
|
+
@diet = diet
|
11
|
+
@exclude = exclude
|
12
|
+
@@all << self
|
13
|
+
end
|
14
|
+
|
15
|
+
def meal_getter
|
16
|
+
@exclude_string = ""
|
17
|
+
@exclude.each {|item| @exclude_string += "#{item}%2C%20"}
|
18
|
+
url = URI("https://spoonacular-recipe-food-nutrition-v1.p.rapidapi.com/recipes/mealplans/generate?timeFrame=#{@time_frame}&targetCalories=#{@target_calories}&diet=#{@diet}&exclude=#{@exclude_string}")
|
19
|
+
|
20
|
+
http = Net::HTTP.new(url.host, url.port)
|
21
|
+
http.use_ssl = true
|
22
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
23
|
+
|
24
|
+
request = Net::HTTP::Get.new(url)
|
25
|
+
request["x-rapidapi-key"] = ENV["X_RAPIDAPI_KEY"]
|
26
|
+
request["x-rapidapi-host"] = 'spoonacular-recipe-food-nutrition-v1.p.rapidapi.com'
|
27
|
+
|
28
|
+
response = http.request(request)
|
29
|
+
@meal_hash = JSON.parse(response.body)
|
30
|
+
@meal_hash
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
end
|
data/lib/processor.rb
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
class Processor
|
2
|
+
|
3
|
+
DATA = {}
|
4
|
+
|
5
|
+
def bond
|
6
|
+
self.time_frame
|
7
|
+
self.target_calories
|
8
|
+
self.diet
|
9
|
+
self.exclude
|
10
|
+
end
|
11
|
+
|
12
|
+
def time_frame
|
13
|
+
puts " ♦♦ What is a time frame for your diet? ♦♦ "
|
14
|
+
puts " ♦♦ 1. Day 2. Week ♦♦ [1/2] "
|
15
|
+
time_frame = gets.chomp
|
16
|
+
if time_frame == '1'
|
17
|
+
DATA[:time_frame] = 'day'
|
18
|
+
elsif time_frame == '2'
|
19
|
+
DATA[:time_frame] = 'week'
|
20
|
+
else
|
21
|
+
puts "♦♦ Please enter 1 to choose a 'day' or 2 for a 'week' ♦♦"
|
22
|
+
self.time_frame
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def target_calories
|
27
|
+
if DATA[:time_frame] == 'day'
|
28
|
+
puts "♦♦ What is your daily target calories, please type in [500-3000] ♦♦"
|
29
|
+
target_calories = gets.chomp
|
30
|
+
self.target_calories if target_calories.to_i > 3000 || target_calories.to_i < 500
|
31
|
+
DATA[:target_calories] = target_calories.to_i
|
32
|
+
end
|
33
|
+
|
34
|
+
if DATA[:time_frame] == 'week'
|
35
|
+
puts "♦♦ What is your weekly target calories, please type in [3000-21000] ♦♦"
|
36
|
+
target_calories = gets.chomp
|
37
|
+
self.target_calories if target_calories.to_i > 21000 || target_calories.to_i < 3000
|
38
|
+
DATA[:target_calories] = target_calories.to_i
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
def diet
|
44
|
+
puts " ♦♦ Do you have a diet preference? ♦♦ "
|
45
|
+
puts "♦♦ 1. none 2. vegeterian 3. pescaterian 4. vegan [type in if other than listed] ♦♦"
|
46
|
+
diet = gets.chomp
|
47
|
+
if diet == '1'
|
48
|
+
DATA[:diet] = 'none'
|
49
|
+
elsif diet == '2'
|
50
|
+
DATA[:diet] = 'vegeterian'
|
51
|
+
elsif diet == '3'
|
52
|
+
DATA[:diet] = 'pescaterian'
|
53
|
+
elsif diet == '4'
|
54
|
+
DATA[:diet] = 'vegan'
|
55
|
+
else
|
56
|
+
DATA[:diet] = diet.split(' ').join('')
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def exclude
|
61
|
+
puts "♦♦ Are you allergic to anything or there is a certain items you would like us to exclude? ♦♦"
|
62
|
+
puts " ♦♦ Please list those items or type in 'none' ♦♦ "
|
63
|
+
exclude_input = gets.chomp
|
64
|
+
exclude_input = exclude_input.split(' ')
|
65
|
+
DATA[:exclude] = exclude_input
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
class SummarizeRecipe
|
2
|
+
|
3
|
+
attr_reader :recipe_summury
|
4
|
+
|
5
|
+
@@all = []
|
6
|
+
|
7
|
+
def initialize(id)
|
8
|
+
@id = id
|
9
|
+
@@all << self
|
10
|
+
end
|
11
|
+
|
12
|
+
def recipe_getter
|
13
|
+
url = URI("https://spoonacular-recipe-food-nutrition-v1.p.rapidapi.com/recipes/#{@id}/summary")
|
14
|
+
|
15
|
+
http = Net::HTTP.new(url.host, url.port)
|
16
|
+
http.use_ssl = true
|
17
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
18
|
+
|
19
|
+
request = Net::HTTP::Get.new(url)
|
20
|
+
request["x-rapidapi-key"] = ENV["X_RAPIDAPI_KEY"]
|
21
|
+
request["x-rapidapi-host"] = 'spoonacular-recipe-food-nutrition-v1.p.rapidapi.com'
|
22
|
+
|
23
|
+
response = http.request(request)
|
24
|
+
@recipe_summury = JSON.parse(response.body)
|
25
|
+
|
26
|
+
@recipe_summury["summary"].gsub!('<b>', '')
|
27
|
+
@recipe_summury["summary"].gsub!('</b>', '')
|
28
|
+
@recipe_summury["summary"].gsub!('<a href=', '')
|
29
|
+
@recipe_summury["summary"].gsub!('</a>', '')
|
30
|
+
@recipe_summury
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
metadata
ADDED
@@ -0,0 +1,122 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dietologist
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Alex Okarkau
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-12-01 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: nokogiri
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: pry
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: Creates a customized diet plan based on your dietary restrictions or
|
84
|
+
allergies
|
85
|
+
email: aokarkau@gmail.com
|
86
|
+
executables:
|
87
|
+
- dietologist
|
88
|
+
extensions: []
|
89
|
+
extra_rdoc_files: []
|
90
|
+
files:
|
91
|
+
- bin/dietologist
|
92
|
+
- config/environment.rb
|
93
|
+
- lib/cli.rb
|
94
|
+
- lib/concerns.rb
|
95
|
+
- lib/dietologist.rb
|
96
|
+
- lib/meal-plan.rb
|
97
|
+
- lib/processor.rb
|
98
|
+
- lib/summarize-recipe.rb
|
99
|
+
homepage: http://rubygems.org/gems/dietologist
|
100
|
+
licenses:
|
101
|
+
- MIT
|
102
|
+
metadata: {}
|
103
|
+
post_install_message:
|
104
|
+
rdoc_options: []
|
105
|
+
require_paths:
|
106
|
+
- lib
|
107
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - ">="
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '0'
|
112
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - ">="
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '0'
|
117
|
+
requirements: []
|
118
|
+
rubygems_version: 3.1.4
|
119
|
+
signing_key:
|
120
|
+
specification_version: 4
|
121
|
+
summary: Custom Diet Plans
|
122
|
+
test_files: []
|