find_recipe 0.2.0 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a0469f0e999a6bed24536d6df513a1aea4818c00
4
- data.tar.gz: fc0a99024555146c134627b222fff336cabca5c3
3
+ metadata.gz: 741f1739d434d1265b98e2fc342f39b0b707a1e4
4
+ data.tar.gz: c9fb6205b1b00b610180b28d69347d8affe6446f
5
5
  SHA512:
6
- metadata.gz: 92dd86ff9275c9ab4d02fd6eadaa8d9160dac29ed5df4efde39d38ba6799dbff10d3f20a9d24c548cf0eb9cee2c308bb8dccbede770de30ef31fb876a5629d9c
7
- data.tar.gz: a3e1152632a03a02643a23dadd76d9bb7ee60c8c2ccf66942ff7c4f5bd24f787915d7ce8ec5ce8ef0538d1d394bd08d9e1cdd21e8ae700744f9116797325348a
6
+ metadata.gz: 225a503df2a3b2d5f0a6f18c365711a57e4f1535fe9a6a2098c3c9f0a9f1d67d4ed9a9f480e3abd12e9acb0ac57ff5e185cfd33528c789a687d22ba9bb597910
7
+ data.tar.gz: 4b1d25169dcc848f5171ad5c3d32633ee1200a54c2b2f31bc5d7fe7bc7188cb7698967837548a7db9e753597ebaca162a36d544397942a9ca3a6c31135975242
data/.gitignore CHANGED
@@ -8,6 +8,9 @@
8
8
  /spec/reports/
9
9
  /tmp/
10
10
 
11
+ # Don't commit gems generated from the source code
12
+ *.gem
13
+
11
14
  # rspec failure tracking
12
15
  .rspec_status
13
16
 
data/README.md CHANGED
@@ -1,6 +1,8 @@
1
+ [![Gem Version](https://badge.fury.io/rb/find_recipe.svg)](https://rubygems.org/gems/find_recipe)
2
+
1
3
  # FindRecipe
2
4
 
3
- This CLI gem helps you get some cooking inspiration directly from your command line! Find a recipe by looking at a list of trending recipes from Cookpad or search with a keyword such as a dish name or ingredient name.
5
+ This CLI gem helps you get some cooking inspiration directly from your command line! Find a recipe by looking at a list of trending recipes from Cookpad or search with a keyword such as a dish name or ingredient name. If you find a recipe that looks good, open it in the browser so you can see the photos or print.
4
6
 
5
7
  ## Installation
6
8
 
@@ -1,5 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require './lib/find_recipe'
3
+ lib_dir = File.realpath('../lib', __dir__)
4
+ $LOAD_PATH.unshift lib_dir
4
5
 
5
- FindRecipe::CLI.new.call
6
+ require 'find_recipe'
7
+ FindRecipe::CLI.new.call
@@ -9,4 +9,4 @@ require_relative "../lib/find_recipe/cli"
9
9
  require_relative "../lib/find_recipe/recipe"
10
10
  require_relative "../lib/find_recipe/searched_recipe"
11
11
  require_relative "../lib/find_recipe/trending_recipe"
12
- require_relative "../lib/find_recipe/scraper"
12
+ require_relative "../lib/find_recipe/scraper"
@@ -26,8 +26,8 @@ Gem::Specification.new do |spec|
26
26
  spec.files = `git ls-files -z`.split("\x0").reject do |f|
27
27
  f.match(%r{^(test|spec|features)/})
28
28
  end
29
- spec.bindir = "exe"
30
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
29
+ spec.bindir = "bin"
30
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
31
31
  spec.require_paths = ["lib"]
32
32
 
33
33
  spec.add_development_dependency "bundler", "~> 1.14"
@@ -1,4 +1,4 @@
1
1
  module FindRecipe
2
2
  end
3
3
 
4
- require_relative '../config/environment'
4
+ require_relative '../config/environment'
@@ -1,6 +1,5 @@
1
1
  # This Class acts as the CLI Controller
2
2
  class FindRecipe::CLI
3
-
4
3
  def call
5
4
  search_options
6
5
  end
@@ -34,7 +33,7 @@ class FindRecipe::CLI
34
33
  puts "Please wait a moment for the recipes to be loaded..."
35
34
 
36
35
  # If search keyword has spaces, it's necessary to replace them with %20 so the URL works
37
- FindRecipe::Recipe::SearchedRecipe.create_recipes( input.gsub( " ", "%20" ) )
36
+ FindRecipe::Recipe::SearchedRecipe.create_recipes(input.gsub(" ", "%20"))
38
37
  end
39
38
  choose_searched_recipes
40
39
  elsif input == "exit"
@@ -47,7 +46,7 @@ class FindRecipe::CLI
47
46
 
48
47
  def trending_recipes
49
48
  puts "\n\n"
50
- FindRecipe::Recipe::TrendingRecipe.all.each.with_index( 1 ) do |recipe, index|
49
+ FindRecipe::Recipe::TrendingRecipe.all.each.with_index(1) do |recipe, index|
51
50
  puts "#{index}.".green + " #{recipe.name}"
52
51
  end
53
52
 
@@ -56,8 +55,8 @@ class FindRecipe::CLI
56
55
 
57
56
  input = gets.strip.downcase
58
57
 
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 ]
58
+ if input.to_i > 0 && input.to_i <= FindRecipe::Recipe::TrendingRecipe.all.size
59
+ chosen_recipe = FindRecipe::Recipe::TrendingRecipe.all[input.to_i - 1]
61
60
  chosen_recipe.get_details
62
61
  elsif input == "back"
63
62
  search_options
@@ -92,7 +91,7 @@ class FindRecipe::CLI
92
91
  puts "\n\n"
93
92
  puts "Search Results:".yellow
94
93
  puts ""
95
- FindRecipe::Recipe::SearchedRecipe.all.each.with_index( 1 ) do |recipe, index|
94
+ FindRecipe::Recipe::SearchedRecipe.all.each.with_index(1) do |recipe, index|
96
95
  puts "#{index}.".green + " #{recipe.name}"
97
96
  end
98
97
 
@@ -101,8 +100,8 @@ class FindRecipe::CLI
101
100
 
102
101
  input = gets.strip.downcase
103
102
 
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 ]
103
+ if input.to_i > 0 && input.to_i <= FindRecipe::Recipe::SearchedRecipe.all.size
104
+ chosen_recipe = FindRecipe::Recipe::SearchedRecipe.all[input.to_i - 1]
106
105
  chosen_recipe.get_details
107
106
  elsif input == "restart"
108
107
  FindRecipe::Recipe::SearchedRecipe.reset
@@ -2,17 +2,17 @@ class FindRecipe::Recipe
2
2
  attr_accessor :name, :description, :ingredients, :steps, :url
3
3
 
4
4
  # Passes in data from scraper when recipe is created
5
- def initialize( recipe_hash )
5
+ def initialize(recipe_hash)
6
6
  recipe_hash.each do |attribute, value|
7
- self.send( ("#{attribute}=" ), value)
7
+ self.send(("#{attribute}="), value)
8
8
  end
9
9
  end
10
10
 
11
11
  def add_additional_recipe_data
12
- additional_recipe_data = FindRecipe::Scraper.scrape_individual_recipe_data( self.url )
12
+ additional_recipe_data = FindRecipe::Scraper.scrape_individual_recipe_data(self.url)
13
13
 
14
14
  additional_recipe_data.each do |attribute, value|
15
- self.send( ("#{attribute}="), value )
15
+ self.send(("#{attribute}="), value)
16
16
  end
17
17
 
18
18
  self
@@ -31,7 +31,7 @@ class FindRecipe::Recipe
31
31
  end
32
32
  puts "\n\n"
33
33
  puts "Steps:".green
34
- @steps.each.with_index( 1 ) do |step, step_number|
34
+ @steps.each.with_index(1) do |step, step_number|
35
35
  puts "#{step_number}.".blue + " #{step}"
36
36
  end
37
37
  puts "\n\n"
@@ -40,4 +40,4 @@ class FindRecipe::Recipe
40
40
  def open_in_browser
41
41
  system("open", self.url)
42
42
  end
43
- end
43
+ end
@@ -4,57 +4,57 @@ class FindRecipe::Scraper
4
4
  def self.scrape_trending_recipes_page
5
5
  recipe_page = self.get_trending_recipes_page
6
6
 
7
- recipe_cards = recipe_page.css( ".card.feed__card" )
7
+ recipe_cards = recipe_page.css(".card.feed__card")
8
8
  recipe_cards.collect do |card|
9
9
  recipe = {
10
- name: card.css( "h2.recipe-title" ).text.strip,
11
- url: ROOT_URL + card.css( "a.link-unstyled" ).attribute( "href" ).value
10
+ name: card.css("h2.recipe-title").text.strip,
11
+ url: ROOT_URL + card.css("a.link-unstyled").attribute("href").value
12
12
  }
13
13
  end.uniq
14
14
  end
15
15
 
16
- def self.scrape_search_page( keyword )
17
- recipe_page = self.get_recipe_page_from_keyword( keyword )
16
+ def self.scrape_search_page(keyword)
17
+ recipe_page = self.get_recipe_page_from_keyword(keyword)
18
18
 
19
- recipe_cards = recipe_page.css( "li.wide-card" )
19
+ recipe_cards = recipe_page.css("li.wide-card")
20
20
  recipe_cards.collect do |card|
21
21
  recipe = {
22
- name: card.css( "h2.recipe-title span" ).text.strip,
23
- url: ROOT_URL + card.css( "a.media" ).attribute( "href" ).value
22
+ name: card.css("h2.recipe-title span").text.strip,
23
+ url: ROOT_URL + card.css("a.media").attribute("href").value
24
24
  }
25
25
  end
26
26
  end
27
27
 
28
- def self.scrape_individual_recipe_data( recipe_url )
28
+ def self.scrape_individual_recipe_data(recipe_url)
29
29
  recipe_data = {}
30
30
 
31
- recipe_page = self.get_individual_recipe_page( recipe_url )
32
- recipe_data[:description] = recipe_page.at( "meta[itemprop='description']" )['content']
31
+ recipe_page = self.get_individual_recipe_page(recipe_url)
32
+ recipe_data[:description] = recipe_page.at("meta[itemprop='description']")['content']
33
33
 
34
34
  # Gets ingredients as an array of each ingredient
35
- recipe_data[:ingredients] = recipe_page.css( ".ingredient__details" ).collect{ |ingredient| ingredient.text.strip }
35
+ recipe_data[:ingredients] = recipe_page.css(".ingredient__details").collect { |ingredient| ingredient.text.strip }
36
36
 
37
37
  # Gets steps as an array of each step
38
- recipe_data[:steps] = recipe_page.css( ".step .prose" ).collect{ |step| step.text.strip }
38
+ recipe_data[:steps] = recipe_page.css(".step .prose").collect { |step| step.text.strip }
39
39
 
40
40
  recipe_data
41
41
  end
42
42
 
43
43
  def self.get_trending_recipes_page
44
44
  url = ROOT_URL + "/uk/trending"
45
- open_url( url )
45
+ open_url(url)
46
46
  end
47
47
 
48
- def self.get_recipe_page_from_keyword( keyword )
48
+ def self.get_recipe_page_from_keyword(keyword)
49
49
  url = ROOT_URL + "/uk/search/#{keyword}"
50
- open_url( url )
50
+ open_url(url)
51
51
  end
52
52
 
53
- def self.get_individual_recipe_page( recipe_url )
54
- open_url( recipe_url )
53
+ def self.get_individual_recipe_page(recipe_url)
54
+ open_url(recipe_url)
55
55
  end
56
56
 
57
- def self.open_url( url )
58
- Nokogiri::HTML( open( url ) )
57
+ def self.open_url(url)
58
+ Nokogiri::HTML(open(url))
59
59
  end
60
- end
60
+ end
@@ -1,13 +1,12 @@
1
1
  class FindRecipe::Recipe::SearchedRecipe < FindRecipe::Recipe
2
-
3
2
  @@all = []
4
3
 
5
4
  # 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 )
5
+ def self.create_recipes(keyword)
6
+ recipe_array = FindRecipe::Scraper.scrape_search_page(keyword)
8
7
 
9
8
  recipes = recipe_array.collect do |recipe|
10
- self.new( recipe )
9
+ self.new(recipe)
11
10
  end
12
11
 
13
12
  # Add remaining attributes from each individual recipe page
@@ -24,4 +23,4 @@ class FindRecipe::Recipe::SearchedRecipe < FindRecipe::Recipe
24
23
  def self.reset
25
24
  @@all.clear
26
25
  end
27
- end
26
+ end
@@ -1,5 +1,4 @@
1
1
  class FindRecipe::Recipe::TrendingRecipe < FindRecipe::Recipe
2
-
3
2
  @@all = []
4
3
 
5
4
  # Create recipes based off an array of recipe data hashes output by the scraper
@@ -7,7 +6,7 @@ class FindRecipe::Recipe::TrendingRecipe < FindRecipe::Recipe
7
6
  recipe_array = FindRecipe::Scraper.scrape_trending_recipes_page
8
7
 
9
8
  recipes = recipe_array.collect do |recipe|
10
- self.new( recipe )
9
+ self.new(recipe)
11
10
  end
12
11
 
13
12
  recipes.each do |recipe|
@@ -19,5 +18,4 @@ class FindRecipe::Recipe::TrendingRecipe < FindRecipe::Recipe
19
18
  def self.all
20
19
  @@all
21
20
  end
22
-
23
- end
21
+ end
@@ -1,3 +1,3 @@
1
1
  module FindRecipe
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
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.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Felice Forby
8
8
  autorequire:
9
- bindir: exe
9
+ bindir: bin
10
10
  cert_chain: []
11
- date: 2018-05-30 00:00:00.000000000 Z
11
+ date: 2018-06-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -105,7 +105,10 @@ description: This CLI app lets you find a recipe from a trending recipe list or
105
105
  and eat well!
106
106
  email:
107
107
  - feliceforby@gmail.com
108
- executables: []
108
+ executables:
109
+ - console
110
+ - find-recipe
111
+ - setup
109
112
  extensions: []
110
113
  extra_rdoc_files: []
111
114
  files:
@@ -121,7 +124,6 @@ files:
121
124
  - bin/find-recipe
122
125
  - bin/setup
123
126
  - config/environment.rb
124
- - find_recipe-0.1.0.gem
125
127
  - find_recipe.gemspec
126
128
  - lib/find_recipe.rb
127
129
  - lib/find_recipe/cli.rb
Binary file