just-the-recipe 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dd7b63f04dd0ef8e6536a0a1ec23db9e26491a2e778d4033615ea7630338a527
4
- data.tar.gz: 27de77e4c6e546a51ed51ef226abd1c85351af531725d093724e0f33c0af0028
3
+ metadata.gz: 7efe12a5ede8904f3753a7f8de9d370fb2e53db6652064e9af41572bba46b886
4
+ data.tar.gz: a815e1d1ab0b0c5b23e94c884537ec889fa614e81c6bbc1d0179cb10429036fd
5
5
  SHA512:
6
- metadata.gz: 2e91e8971c95aada57382c7c799d887c0257fb03d43f81f0b3a2c84704e9a9070033b567416c88212cf8b6e47a79da04316fbf69d595c9e6fff513d2e81f05ef
7
- data.tar.gz: f267754a184f11536aa1f4c96933cdd1d70c333720e66088d66b51bbda2bcad10968e46a62cd26d0c3742c044dfeed1d7ba93f8c32bf8741921e4e63951f6cc5
6
+ metadata.gz: 5bd498673d49f389862ed7e4a3fc52baea5672d3025a52a22b7c7a1123e97bcd2359d3130d06c595259ea8a68c56d26a8543917e658664f01bf1e0f94203aebc
7
+ data.tar.gz: 1eae0d9e9bfdb55093c2a3bf8ed5ea8fe30ec803584014e94c6a2698365ab6704a24681dea954c9a15d892c30916b79641125fdaecc7193eb4826981719d354a
data/.env.template ADDED
@@ -0,0 +1,2 @@
1
+ APP_ID =APP_ID
2
+ APP_KEY =APP_KEY
data/Gemfile.lock CHANGED
@@ -1,10 +1,11 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- just-the-recipe (0.1.0)
4
+ just-the-recipe (0.2.0)
5
5
  dotenv
6
6
  nokogiri
7
7
  open-uri
8
+ tty-prompt
8
9
 
9
10
  GEM
10
11
  remote: https://rubygems.org/
@@ -13,8 +14,21 @@ GEM
13
14
  nokogiri (1.11.2-x86_64-darwin)
14
15
  racc (~> 1.4)
15
16
  open-uri (0.1.0)
17
+ pastel (0.8.0)
18
+ tty-color (~> 0.5)
16
19
  racc (1.5.2)
17
20
  rake (13.0.3)
21
+ tty-color (0.6.0)
22
+ tty-cursor (0.7.1)
23
+ tty-prompt (0.23.0)
24
+ pastel (~> 0.8)
25
+ tty-reader (~> 0.8)
26
+ tty-reader (0.9.0)
27
+ tty-cursor (~> 0.7)
28
+ tty-screen (~> 0.8)
29
+ wisper (~> 2.0)
30
+ tty-screen (0.8.1)
31
+ wisper (2.0.1)
18
32
 
19
33
  PLATFORMS
20
34
  x86_64-darwin-20
@@ -15,7 +15,7 @@ Gem::Specification.new do |spec|
15
15
 
16
16
  spec.metadata["allowed_push_host"] = "https://rubygems.org/"
17
17
 
18
- spec.metadata["homepage_uri"] = spec.homepage
18
+ spec.metadata["homepage_uri"] = "https://github.com/george-dilthey/just-the-recipe"
19
19
  spec.metadata["source_code_uri"] = "https://github.com/george-dilthey/just-the-recipe"
20
20
  spec.metadata["changelog_uri"] = "https://github.com/george-dilthey/just-the-recipe"
21
21
 
@@ -32,6 +32,7 @@ Gem::Specification.new do |spec|
32
32
  spec.add_dependency "open-uri"
33
33
  spec.add_dependency "dotenv"
34
34
  spec.add_dependency "nokogiri"
35
+ spec.add_dependency "tty-prompt"
35
36
 
36
37
  # For more information and examples about making a new gem, checkout our
37
38
  # guide at: https://bundler.io/guides/creating_gem.html
data/lib/environment.rb CHANGED
@@ -3,6 +3,9 @@ require 'open-uri'
3
3
  require 'nokogiri'
4
4
  require 'JSON'
5
5
  require 'net/http'
6
+ require 'tty-prompt'
7
+
8
+ Dotenv.require_keys("APP_ID", "APP_KEY")
6
9
 
7
10
  require './lib/just-the-recipe/version.rb'
8
11
  require './lib/just-the-recipe/cli.rb'
@@ -5,65 +5,31 @@ class JustTheRecipe::CLI
5
5
  def call
6
6
  JustTheRecipe::Cookbook.create_from_files
7
7
  puts "Welcome to Just the Recipe! What would you like to do?"
8
- list_options
9
- choose_option
10
- goodbye
8
+ main_menu
11
9
  end
12
10
 
13
- def list_options
14
- puts "\n\nEnter a number 1-3 or type exit."
15
- puts "1. Search for a new recipe."
16
- puts "2. Get a recipe from a url."
17
- puts "3. View your cookbooks."
18
- end
19
-
20
- def choose_option
21
- input = nil
22
- while input != "exit"
23
- input = gets.chomp
24
- if input == "1"
25
- search
26
- elsif input == "2"
27
- scrape_url
28
- elsif input == "3"
29
- cookbook_menu
30
- elsif input == "exit"
31
- break
32
- elsif input == "options"
33
- list_options
34
- else
35
- puts "Whoops! Choose a number 1-3, type options to view your options again, or type exit."
36
- end
11
+ def main_menu
12
+ prompt = TTY::Prompt.new
13
+ puts "\n"
14
+ menu_choice = prompt.select("Choose an option") do |menu|
15
+ menu.choice name: "Search for a new recipe.", value: 1
16
+ menu.choice name: "Get a recipe from a URL.", value: 2
17
+ menu.choice name: "View your cookbooks.", value: 3
18
+ menu.choice name: "Create a new recipe manually.", value: 4
19
+ menu.choice name: "Exit", value: "exit"
37
20
  end
38
- end
39
21
 
40
- def scrape_url
41
- puts "Enter your url:"
42
- url = gets.chomp
43
- if JustTheRecipe::Scraper.new(url).valid_url?
44
- recipe = JustTheRecipe::Scraper.new(url).get_recipe_by_schema
45
- recipe.display_recipe
46
- add_recipe(recipe)
47
- list_options
48
- else
49
- puts ""
50
- puts "Sorry, it doesn't look like we can get the recipe from that URL. Try something else."
51
- list_options
52
- end
53
- end
54
-
55
- def add_recipe(recipe)
56
- puts "Would you like to add this recipe to a cookbook? (y/n)"
57
- input = gets.chomp
58
- if input == "y"
59
- puts "Ok! Which cookbook would you like to add this recipe to? Type an existing cookbook name, or type anything to create a new one!"
60
- cookbook = gets.chomp
61
- recipe.add_to_cookbook(cookbook)
62
- puts "Great choice. We added this recipe to the cookbook called #{cookbook}"
63
- elsif input == "n"
64
- puts "No problem. This recipe wasn't added to a cookbook."
65
- else
66
- puts "Sorry, you'll have to answer with either 'y' or 'n'."
22
+ case menu_choice
23
+ when 1
24
+ search
25
+ when 2
26
+ scrape_url
27
+ when 3
28
+ cookbook_menu
29
+ when 4
30
+ new_recipe
31
+ when "exit"
32
+ goodbye
67
33
  end
68
34
  end
69
35
 
@@ -74,44 +40,99 @@ class JustTheRecipe::CLI
74
40
  if recipe.class == JustTheRecipe::Recipe
75
41
  recipe.display_recipe
76
42
  add_recipe(recipe)
77
- list_options
78
43
  else
79
- list_options
44
+ main_menu
80
45
  end
81
46
  end
82
47
 
83
- def cookbook_menu
84
- if JustTheRecipe::Cookbook.all.length > 0
85
- puts "Type the name of the cookbook you'd like to view, type \"create\" to create a new one, type \"delete\" to delete a cookbook, or type \"exit\" to return to the main menu.\n\n"
86
- JustTheRecipe::Cookbook.list_cookbooks
48
+ def scrape_url
49
+ puts "Enter your url:"
50
+ url = gets.chomp
51
+ if JustTheRecipe::Scraper.new(url).valid_url?
52
+ recipe = JustTheRecipe::Scraper.new(url).get_recipe_by_schema
53
+ recipe.display_recipe
54
+ add_recipe(recipe)
87
55
  else
88
- puts "It looks like you don't have any cookbooks yet. Type \"create\" to create a new one, or type \"exit\" to return to the main menu."
56
+ puts "\nSorry, it doesn't look like we can get the recipe from that URL. Try something else."
57
+ main_menu
89
58
  end
90
- input = gets.chomp
59
+ end
91
60
 
61
+ def cookbook_menu
62
+ prompt = TTY::Prompt.new
63
+
64
+ cookbooks_create = JustTheRecipe::Cookbook.list_cookbooks << "Create a new cookbook." << "Delete a cookbook." << "Main Menu"
65
+ input = prompt.select("Choose a cookbook to view or create a new one.", cookbooks_create)
66
+ JustTheRecipe::Cookbook.list_cookbooks
67
+
92
68
  if JustTheRecipe::Cookbook.find_by_name(input)
93
69
  puts "Here's what's in the cookbook called #{input}:"
94
70
  puts JustTheRecipe::Cookbook.find_by_name(input).return_cookbook
95
- list_options
96
- elsif input == "create"
97
- puts "Ok! What would you like to name your new cookbook?"
98
- cookbook = gets.chomp
99
- JustTheRecipe::Cookbook.new(cookbook)
100
- puts "Great! We created a new cookbook for you. Find some recipes to add to it!"
101
- list_options
102
- elsif input == "delete"
103
- puts "Which cookbook would you like to delete? WARNING: THIS CANNOT BE UNDONE!\n\n"
104
- JustTheRecipe::Cookbook.list_cookbooks
105
- delete_cookbook = gets.chomp
106
- JustTheRecipe::Cookbook.delete(delete_cookbook)
71
+ main_menu
72
+ elsif input == "Create a new cookbook"
73
+ create_cookbook
74
+ main_menu
75
+ elsif input == "Delete a cookbook."
76
+ cookbooks_delete = JustTheRecipe::Cookbook.list_cookbooks << "Exit"
77
+ delete = prompt.select("Which cookbook would you like to delete? WARNING: THIS CANNOT BE UNDONE!", cookbooks_create)
78
+ JustTheRecipe::Cookbook.delete(delete)
107
79
  puts "Ok, we deleted that cookbook."
108
- list_options
109
- elsif input == "exit"
110
- list_options
80
+ main_menu
81
+ elsif input == "Main Menu"
82
+ main_menu
83
+ end
84
+ end
85
+
86
+ def new_recipe
87
+ puts "Ok, what would you like to call your new recipe?"
88
+ name = gets.chomp
89
+
90
+ puts "Add a short description of your recipe."
91
+ description = gets.chomp
92
+
93
+ puts "Add the recipe's ingredients, seperated by a comma. (Ex: 1/2 cup of flour, 2 tbsp sugar, 1 cup water)"
94
+ ingredients = gets.chomp.split(", ")
95
+
96
+ puts "Add the recipe's instructions, seperated by a comma. (Ex: Mix the ingredients, cook the recipe, enjoy!)"
97
+ steps = gets.chomp.split(", ")
98
+
99
+ puts "\nGreat! Here's your new recipe:"
100
+ manual_recipe = JustTheRecipe::Recipe.new(name, description, ingredients, steps)
101
+ manual_recipe.display_recipe
102
+ add_recipe(manual_recipe)
103
+ end
104
+
105
+ def create_cookbook
106
+ puts "Ok! What would you like to name your new cookbook?"
107
+ cookbook = gets.chomp
108
+ JustTheRecipe::Cookbook.new(cookbook)
109
+ puts "Great! We created a new cookbook for you."
110
+ cookbook
111
+ end
112
+
113
+ def add_recipe(recipe)
114
+ prompt = TTY::Prompt.new
115
+ puts "Would you like to add this recipe to a cookbook? It won't be saved otherwise. (y/n)"
116
+ input = gets.chomp
117
+ if input == "y"
118
+
119
+ cookbooks_create = JustTheRecipe::Cookbook.list_cookbooks << "Create a new cookbook."
120
+ cookbook = prompt.select("Ok! Choose a cookbook to add your recipe to, or create a new one.", cookbooks_create)
121
+ if cookbook == "Create a new cookbook."
122
+ recipe.add_to_cookbook(create_cookbook)
123
+ puts "We added this recipe to your new cookbook."
124
+ main_menu
125
+ else
126
+ recipe.add_to_cookbook(cookbook)
127
+ puts "We added this recipe to the cookbook called #{cookbook}"
128
+ main_menu
129
+ end
130
+ elsif input == "n"
131
+ puts "No problem. This recipe wasn't added to a cookbook."
132
+ main_menu
111
133
  else
112
- puts ""
113
- puts "Sorry, thats not a valid cookbook. Type \"create\" to create a new cookbook or type \"exit\" to return to the main menu"
114
- list_cookbooks
134
+ puts "Sorry, you'll have to answer with either 'y' or 'n'."
135
+ main_menu
115
136
  end
116
137
  end
117
138
 
@@ -42,7 +42,9 @@ class JustTheRecipe::Cookbook
42
42
  end
43
43
 
44
44
  def self.list_cookbooks
45
- @@all.each{|i| puts "#{i.name}"}
45
+ cookbooks = []
46
+ @@all.each{|i| cookbooks << i.name}
47
+ cookbooks
46
48
  end
47
49
 
48
50
  def return_cookbook
@@ -7,7 +7,7 @@ class JustTheRecipe::Recipe
7
7
 
8
8
  @@all = []
9
9
 
10
- def initialize(title, description, ingredients, steps, url) # ingredients and steps are arrays
10
+ def initialize(title, description, ingredients, steps, url= "n/a") # ingredients and steps are arrays
11
11
  @title = title
12
12
  @description = description
13
13
  @ingredients = ingredients
@@ -34,7 +34,6 @@ class JustTheRecipe::Searcher
34
34
  scrape_recipe(good_url)
35
35
  rescue
36
36
  puts "Sorry we couldn't find a valid recipe with that search term."
37
- puts e
38
37
  end
39
38
 
40
39
  end
@@ -1,3 +1,3 @@
1
1
  module JustTheRecipe
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
data/notes.md ADDED
@@ -0,0 +1,4 @@
1
+
2
+ 1. Refactor with TTY-prompt
3
+ 2. Fix error when API returns nothing.
4
+ 3. Figure out gem stuff
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: just-the-recipe
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - George Dilthey
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-03-22 00:00:00.000000000 Z
11
+ date: 2021-03-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: open-uri
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: tty-prompt
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
55
69
  description: A small CLI application to search for recipes and create simple cookbooks.
56
70
  email:
57
71
  - george.dilthey@gmail.com
@@ -60,6 +74,7 @@ extensions: []
60
74
  extra_rdoc_files: []
61
75
  files:
62
76
  - ".DS_Store"
77
+ - ".env.template"
63
78
  - ".gitignore"
64
79
  - Gemfile
65
80
  - Gemfile.lock
@@ -76,6 +91,7 @@ files:
76
91
  - lib/just-the-recipe/scraper.rb
77
92
  - lib/just-the-recipe/searcher.rb
78
93
  - lib/just-the-recipe/version.rb
94
+ - notes.md
79
95
  homepage: https://github.com/george-dilthey/just-the-recipe
80
96
  licenses: []
81
97
  metadata: