just-the-recipe 0.1.0 → 0.6.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: 9f762feff2c616419e85ce6ddf071c889643531c3f90b3934d06b5356f9e4282
4
+ data.tar.gz: e3ecdd69fc59b935137748d66afec24371466c6bc336c166ff917c45daab569d
5
5
  SHA512:
6
- metadata.gz: 2e91e8971c95aada57382c7c799d887c0257fb03d43f81f0b3a2c84704e9a9070033b567416c88212cf8b6e47a79da04316fbf69d595c9e6fff513d2e81f05ef
7
- data.tar.gz: f267754a184f11536aa1f4c96933cdd1d70c333720e66088d66b51bbda2bcad10968e46a62cd26d0c3742c044dfeed1d7ba93f8c32bf8741921e4e63951f6cc5
6
+ metadata.gz: 9dcc649793cdac6c6a99e4e04243954c9869da5c809f85ccc8f2e71c0e204fd43e72a8e052db17ca51f719d9d0c6229af239c1436b23d219e74212c36eba3431
7
+ data.tar.gz: 3a87384a00dbfc2742d37323f1f1cd745a09bd53440cf0dfd34c408775cb28a8991148513d703caef5da5f67e9298ab58dc288b2824476cf724b62fd5b0f2549
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.6.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
data/README.md CHANGED
@@ -4,8 +4,7 @@
4
4
 
5
5
  Add this line to your application's Gemfile:
6
6
 
7
- ```ruby
8
- gem 'just-the-recipe'
7
+ ```ruby gem 'just-the-recipe'
9
8
  ```
10
9
 
11
10
  And then execute:
data/bin/console CHANGED
@@ -2,7 +2,7 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require "bundler/setup"
5
- require "./lib/environment.rb"
5
+ require './lib/just-the-recipe.rb'
6
6
 
7
7
  # You can add fixtures and/or initialization code here to make experimenting
8
8
  # with your gem easier. You can also use a different console, if you like.
data/bin/just-the-recipe CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
2
  require "bundler/setup"
3
- require "./lib/environment.rb"
3
+ require './lib/just-the-recipe.rb'
4
4
 
5
5
  JustTheRecipe::CLI.new.call
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "./lib/environment.rb"
3
+ require "./lib/just-the-recipe.rb"
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = "just-the-recipe"
@@ -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
 
@@ -24,14 +24,15 @@ Gem::Specification.new do |spec|
24
24
  spec.files = Dir.chdir(File.expand_path(__dir__)) do
25
25
  `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
26
26
  end
27
- spec.bindir = "exe"
28
- spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
27
+ spec.bindir = "bin"
28
+ spec.executables = spec.files.grep(%r{\Abin/}) { |f| File.basename(f) }
29
29
  spec.require_paths = ["lib"]
30
30
 
31
31
  # Uncomment to register a new dependency of your gem
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
@@ -3,6 +3,7 @@ require 'open-uri'
3
3
  require 'nokogiri'
4
4
  require 'JSON'
5
5
  require 'net/http'
6
+ require 'tty-prompt'
6
7
 
7
8
  require './lib/just-the-recipe/version.rb'
8
9
  require './lib/just-the-recipe/cli.rb'
@@ -0,0 +1,11 @@
1
+
2
+ class Authenticate
3
+
4
+ def initialize(app_id, app_key)
5
+ @app_id, @app_key = app_id, app_key
6
+ File.write(".env", "APP_ID = #{app_id.to_s}\nAPP_KEY = #{app_key.to_s}")
7
+ end
8
+
9
+ end
10
+
11
+ Authenticate.new('6d8b7767', 'e1633ded1da9906633b79ec6c8525ac5')
@@ -1,69 +1,35 @@
1
- require_relative '../environment.rb'
1
+ require './lib/just-the-recipe.rb'
2
2
 
3
3
  class JustTheRecipe::CLI
4
4
 
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
37
- end
38
- end
39
-
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
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"
52
20
  end
53
- end
54
21
 
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
 
@@ -119,4 +140,6 @@ class JustTheRecipe::CLI
119
140
  puts "\n\nThanks for stopping by! If you created any cookbooks, they'll be saved as text files so that you can continue using them in the future. See you soon!"
120
141
  end
121
142
 
143
+
144
+
122
145
  end
@@ -1,5 +1,5 @@
1
1
  require 'pry'
2
- require './lib/environment.rb'
2
+ require './lib/just-the-recipe.rb'
3
3
 
4
4
  class JustTheRecipe::Cookbook
5
5
 
@@ -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
@@ -1,5 +1,5 @@
1
1
  require 'pry'
2
- require './lib/environment.rb'
2
+ require './lib/just-the-recipe.rb'
3
3
 
4
4
  class JustTheRecipe::Recipe
5
5
 
@@ -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
@@ -1,6 +1,6 @@
1
1
  require 'pry'
2
2
 
3
- require './lib/environment.rb'
3
+ require './lib/just-the-recipe.rb'
4
4
 
5
5
  class JustTheRecipe::Scraper
6
6
 
@@ -1,6 +1,6 @@
1
1
  require 'pry'
2
2
 
3
- require './lib/environment.rb'
3
+ require './lib/just-the-recipe.rb'
4
4
 
5
5
  class JustTheRecipe::Searcher
6
6
 
@@ -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.6.0"
3
3
  end
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.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - George Dilthey
8
8
  autorequire:
9
- bindir: exe
9
+ bindir: bin
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,10 +52,27 @@ 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
58
- executables: []
72
+ executables:
73
+ - console
74
+ - just-the-recipe
75
+ - setup
59
76
  extensions: []
60
77
  extra_rdoc_files: []
61
78
  files:
@@ -69,7 +86,8 @@ files:
69
86
  - bin/just-the-recipe
70
87
  - bin/setup
71
88
  - just-the-recipe.gemspec
72
- - lib/environment.rb
89
+ - lib/just-the-recipe.rb
90
+ - lib/just-the-recipe/authenticate.rb
73
91
  - lib/just-the-recipe/cli.rb
74
92
  - lib/just-the-recipe/cookbook.rb
75
93
  - lib/just-the-recipe/recipe.rb