find_recipe 0.1.0 → 0.2.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 18e9f6c1e1dc8b7c5323f2799d65320a07f07941
4
- data.tar.gz: 152d2441751d34a2a573ad35272267ea1239b36f
3
+ metadata.gz: a0469f0e999a6bed24536d6df513a1aea4818c00
4
+ data.tar.gz: fc0a99024555146c134627b222fff336cabca5c3
5
5
  SHA512:
6
- metadata.gz: fa77a12b522dff5aa252c4f4fbafc73f7e7c1d0c4e478506a7f41e0af1f155da99a61d29275c3c864204dd7f8f1db64329f9f34268e4a5bbe869ac2a6d94f3ad
7
- data.tar.gz: '057578a1bf966c2880ec426f040823e07c1139af2a034cacfc3f2dbf5c535a9e61154a08dc4b6f02d5d2f2ca9b713346022988c339ed4d4f979a5e2cc54f5f02'
6
+ metadata.gz: 92dd86ff9275c9ab4d02fd6eadaa8d9160dac29ed5df4efde39d38ba6799dbff10d3f20a9d24c548cf0eb9cee2c308bb8dccbede770de30ef31fb876a5629d9c
7
+ data.tar.gz: a3e1152632a03a02643a23dadd76d9bb7ee60c8c2ccf66942ff7c4f5bd24f787915d7ce8ec5ce8ef0538d1d394bd08d9e1cdd21e8ae700744f9116797325348a
data/.gitignore CHANGED
@@ -10,3 +10,13 @@
10
10
 
11
11
  # rspec failure tracking
12
12
  .rspec_status
13
+
14
+ # OS generated files #
15
+ ######################
16
+ .DS_Store
17
+ .DS_Store?
18
+ ._*
19
+ .Spotlight-V100
20
+ .Trashes
21
+ ehthumbs.db
22
+ Thumbs.db
@@ -0,0 +1,12 @@
1
+ require 'open-uri'
2
+ require 'nokogiri'
3
+ require 'colorize'
4
+ # Uncomment below if you need to use pry for debugging, etc.
5
+ # require 'pry'
6
+
7
+ require_relative "../lib/find_recipe/version"
8
+ require_relative "../lib/find_recipe/cli"
9
+ require_relative "../lib/find_recipe/recipe"
10
+ require_relative "../lib/find_recipe/searched_recipe"
11
+ require_relative "../lib/find_recipe/trending_recipe"
12
+ require_relative "../lib/find_recipe/scraper"
Binary file
data/lib/find_recipe.rb CHANGED
@@ -1,15 +1,4 @@
1
- # Loads the needed files.
2
- require 'open-uri'
3
- require 'nokogiri'
4
- require 'colorize'
5
- # Uncomment below if you need to use pry for debugging, etc.
6
- # require 'pry'
7
-
8
- require_relative "find_recipe/version"
9
-
10
1
  module FindRecipe
11
2
  end
12
3
 
13
- require_relative "find_recipe/cli"
14
- require_relative "find_recipe/recipe"
15
- require_relative "find_recipe/scraper"
4
+ require_relative '../config/environment'
@@ -20,21 +20,21 @@ class FindRecipe::CLI
20
20
  if input == "1"
21
21
 
22
22
  # Scrapes recipes only once to save loading time
23
- if !@trending_recipes
23
+ if FindRecipe::Recipe::TrendingRecipe.all.size == 0
24
24
  puts "Please wait a moment for the recipes to be loaded..."
25
- @trending_recipes = FindRecipe::Recipe.create_recipes
25
+ FindRecipe::Recipe::TrendingRecipe.create_recipes
26
26
  end
27
27
  trending_recipes
28
28
  elsif input == "2"
29
29
 
30
30
  # Scrape recipes only if a search hasn't been done yet or if user restarts
31
- if !@searched_recipes || @searched_recipes.length == 0
31
+ if FindRecipe::Recipe::SearchedRecipe.all.size == 0
32
32
  puts "What is the dish or ingredient you want to search for?"
33
33
  input = gets.strip.downcase
34
34
  puts "Please wait a moment for the recipes to be loaded..."
35
35
 
36
36
  # If search keyword has spaces, it's necessary to replace them with %20 so the URL works
37
- @searched_recipes = FindRecipe::Recipe.create_recipes( input.gsub( " ", "%20" ) )
37
+ FindRecipe::Recipe::SearchedRecipe.create_recipes( input.gsub( " ", "%20" ) )
38
38
  end
39
39
  choose_searched_recipes
40
40
  elsif input == "exit"
@@ -43,12 +43,11 @@ class FindRecipe::CLI
43
43
  puts "Not sure what you mean..."
44
44
  search_options
45
45
  end
46
-
47
46
  end
48
47
 
49
48
  def trending_recipes
50
49
  puts "\n\n"
51
- @trending_recipes.each.with_index( 1 ) do |recipe, index|
50
+ FindRecipe::Recipe::TrendingRecipe.all.each.with_index( 1 ) do |recipe, index|
52
51
  puts "#{index}.".green + " #{recipe.name}"
53
52
  end
54
53
 
@@ -57,8 +56,9 @@ class FindRecipe::CLI
57
56
 
58
57
  input = gets.strip.downcase
59
58
 
60
- if input.to_i > 0 && input.to_i <= @trending_recipes.count
61
- @trending_recipes[ input.to_i - 1 ].get_details
59
+ if input.to_i > 0 && input.to_i <= FindRecipe::Recipe::TrendingRecipe.all.count
60
+ chosen_recipe = FindRecipe::Recipe::TrendingRecipe.all[ input.to_i - 1 ]
61
+ chosen_recipe.get_details
62
62
  elsif input == "back"
63
63
  search_options
64
64
  else
@@ -67,6 +67,14 @@ class FindRecipe::CLI
67
67
  trending_recipes
68
68
  end
69
69
 
70
+ puts "Open in browser? (y/n)"
71
+
72
+ input = gets.strip.downcase
73
+
74
+ if input == "y"
75
+ chosen_recipe.open_in_browser
76
+ end
77
+
70
78
  puts "Do you want to see the list again, restart, or exit?"
71
79
  puts "Enter list, restart, or exit"
72
80
  input = gets.strip.downcase
@@ -78,14 +86,13 @@ class FindRecipe::CLI
78
86
  elsif input == "exit"
79
87
  exit_program
80
88
  end
81
-
82
89
  end
83
90
 
84
91
  def choose_searched_recipes
85
92
  puts "\n\n"
86
93
  puts "Search Results:".yellow
87
94
  puts ""
88
- @searched_recipes.each.with_index( 1 ) do |recipe, index|
95
+ FindRecipe::Recipe::SearchedRecipe.all.each.with_index( 1 ) do |recipe, index|
89
96
  puts "#{index}.".green + " #{recipe.name}"
90
97
  end
91
98
 
@@ -94,16 +101,25 @@ class FindRecipe::CLI
94
101
 
95
102
  input = gets.strip.downcase
96
103
 
97
- if input.to_i > 0 && input.to_i <= @searched_recipes.count
98
- @searched_recipes[ input.to_i - 1 ].get_details
104
+ if input.to_i > 0 && input.to_i <= FindRecipe::Recipe::SearchedRecipe.all.count
105
+ chosen_recipe = FindRecipe::Recipe::SearchedRecipe.all[ input.to_i - 1 ]
106
+ chosen_recipe.get_details
99
107
  elsif input == "restart"
100
- @searched_recipes.clear
108
+ FindRecipe::Recipe::SearchedRecipe.reset
101
109
  search_options
102
110
  else
103
111
  puts "Not sure what you mean..."
104
112
  choose_searched_recipes
105
113
  end
106
-
114
+
115
+ puts "Open in browser? (y/n)"
116
+
117
+ input = gets.strip.downcase
118
+
119
+ if input == "y"
120
+ chosen_recipe.open_in_browser
121
+ end
122
+
107
123
  puts "Do you want to see the list again, restart, or exit?"
108
124
  puts "Enter list, restart, or exit"
109
125
  input = gets.strip.downcase
@@ -111,17 +127,15 @@ class FindRecipe::CLI
111
127
  if input == "list"
112
128
  choose_searched_recipes
113
129
  elsif input == "restart"
114
- @searched_recipes.clear
130
+ FindRecipe::Recipe::SearchedRecipe.reset
115
131
  search_options
116
132
  elsif input == "exit"
117
133
  exit_program
118
134
  end
119
-
120
135
  end
121
136
 
122
137
  def exit_program
123
138
  puts "See you next time!"
124
139
  exit
125
140
  end
126
-
127
141
  end
@@ -8,29 +8,13 @@ class FindRecipe::Recipe
8
8
  end
9
9
  end
10
10
 
11
- # Create recipes based off an array of recipe data hashes output by the scraper
12
- def self.create_recipes( keyword = nil )
13
- if keyword
14
- recipe_array = FindRecipe::Scraper.scrape_search_page( keyword )
15
- else
16
- recipe_array = FindRecipe::Scraper.scrape_trending_recipes_page
17
- end
18
-
19
- recipes = recipe_array.collect do |recipe|
20
- self.new( recipe )
21
- end
11
+ def add_additional_recipe_data
12
+ additional_recipe_data = FindRecipe::Scraper.scrape_individual_recipe_data( self.url )
22
13
 
23
- # Add remaining attributes from each individual recipe page
24
- recipes.each do |recipe|
25
- additional_recipe_data = FindRecipe::Scraper.scrape_individual_recipe_data( recipe.url )
26
- recipe.add_additional_recipe_data( additional_recipe_data )
27
- end
28
- end
29
-
30
- def add_additional_recipe_data( data_hash )
31
- data_hash.each do |attribute, value|
14
+ additional_recipe_data.each do |attribute, value|
32
15
  self.send( ("#{attribute}="), value )
33
16
  end
17
+
34
18
  self
35
19
  end
36
20
 
@@ -53,5 +37,7 @@ class FindRecipe::Recipe
53
37
  puts "\n\n"
54
38
  end
55
39
 
56
-
40
+ def open_in_browser
41
+ system("open", self.url)
42
+ end
57
43
  end
@@ -0,0 +1,27 @@
1
+ class FindRecipe::Recipe::SearchedRecipe < FindRecipe::Recipe
2
+
3
+ @@all = []
4
+
5
+ # Create recipes based off an array of recipe data hashes output by the scraper
6
+ def self.create_recipes( keyword )
7
+ recipe_array = FindRecipe::Scraper.scrape_search_page( keyword )
8
+
9
+ recipes = recipe_array.collect do |recipe|
10
+ self.new( recipe )
11
+ end
12
+
13
+ # Add remaining attributes from each individual recipe page
14
+ recipes.each do |recipe|
15
+ recipe.add_additional_recipe_data
16
+ @@all << recipe
17
+ end
18
+ end
19
+
20
+ def self.all
21
+ @@all
22
+ end
23
+
24
+ def self.reset
25
+ @@all.clear
26
+ end
27
+ end
@@ -0,0 +1,23 @@
1
+ class FindRecipe::Recipe::TrendingRecipe < FindRecipe::Recipe
2
+
3
+ @@all = []
4
+
5
+ # Create recipes based off an array of recipe data hashes output by the scraper
6
+ def self.create_recipes
7
+ recipe_array = FindRecipe::Scraper.scrape_trending_recipes_page
8
+
9
+ recipes = recipe_array.collect do |recipe|
10
+ self.new( recipe )
11
+ end
12
+
13
+ recipes.each do |recipe|
14
+ recipe.add_additional_recipe_data
15
+ @@all << recipe
16
+ end
17
+ end
18
+
19
+ def self.all
20
+ @@all
21
+ end
22
+
23
+ end
@@ -1,3 +1,3 @@
1
1
  module FindRecipe
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: find_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
  - Felice Forby
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-05-27 00:00:00.000000000 Z
11
+ date: 2018-05-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -120,11 +120,15 @@ files:
120
120
  - bin/console
121
121
  - bin/find-recipe
122
122
  - bin/setup
123
+ - config/environment.rb
124
+ - find_recipe-0.1.0.gem
123
125
  - find_recipe.gemspec
124
126
  - lib/find_recipe.rb
125
127
  - lib/find_recipe/cli.rb
126
128
  - lib/find_recipe/recipe.rb
127
129
  - lib/find_recipe/scraper.rb
130
+ - lib/find_recipe/searched_recipe.rb
131
+ - lib/find_recipe/trending_recipe.rb
128
132
  - lib/find_recipe/version.rb
129
133
  - planning_notes.md
130
134
  - spec.md