top-recipes 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e5198ccbc905e56e9ba06ca3bbbc9b6545ff1929
4
+ data.tar.gz: f09a7d0bbc1a15973addd86a8356ded62cf56727
5
+ SHA512:
6
+ metadata.gz: dcae9743c4cf564bf6b00adf4fdbac88e8165480b42c5d6f734159864a6df5bbc2643c11a4442d34c2eeb8db9a23765df05660f9fcd9eef769357ff73205c7ae
7
+ data.tar.gz: ca8fc1e51e79631e6f20185c14a2c2b2921dad5f7b0f91995d571fdfb4373232da8031e8a37f63467230f6b17f30842b98dc1b3f211061628c0e2b58180ca11a
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in top_recipes.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,33 @@
1
+ # TopRecipes
2
+
3
+ This gem is a CLI to browse through the latest recipes on food2fork with some humor involved.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'top_recipes'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install top_recipes
20
+
21
+ ## Usage
22
+
23
+ Run the gem, and ask her to list you recipes with the 'list recipes' command. And look into the details of the recipe by pressing the recipe number. Ask her to tell you a joke. Happy Cooking :)
24
+
25
+ ## Development
26
+
27
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
28
+
29
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
30
+
31
+ ## Contributing
32
+
33
+ Bug reports and pull requests are welcome on GitHub at https://github.com/mxdavis/recipes-from-food2fork-cli.
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative '../lib/top_recipes'
4
+
5
+ require "irb"
6
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
data/bin/top-recipes ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative '../lib/top_recipes'
4
+
5
+ TopRecipes::CLI.start
@@ -0,0 +1,9 @@
1
+ require "open-uri"
2
+ require "nokogiri"
3
+ require "pry"
4
+
5
+ require_relative "./top_recipes/version"
6
+ require_relative "./top_recipes/cli"
7
+ require_relative "./top_recipes/recipe"
8
+ require_relative "./top_recipes/scraper"
9
+ require_relative "./top_recipes/jokes"
@@ -0,0 +1,125 @@
1
+ class TopRecipes::CLI
2
+
3
+ @input = nil
4
+
5
+ def self.start
6
+ puts "Greetings! Give me a minute while I load up some of the best recipes for you!"
7
+
8
+ TopRecipes::Scraper.scrape_and_create_recipes_food2fork
9
+
10
+ self.greeting
11
+ end
12
+
13
+ def self.greeting
14
+ self.line_break
15
+ puts "Hello! Please ask me to show you some of my latest recipes by typing 'list recipes'. You can also ask me to tell you a joke by typing 'joke'. You can also type 'exit' or 'bye' when you need to go."
16
+
17
+ @input = gets.strip
18
+
19
+ self.possible_commands
20
+ end
21
+
22
+ def self.list_recipes
23
+ self.line_break
24
+ if TopRecipes::Recipe.top_recipes.size > 0
25
+ puts "Here are the top trending recipes of today:"
26
+ TopRecipes::Recipe.top_recipes.each.with_index(1) do |r, i|
27
+ puts "#{i}. #{r.name} by #{r.author} with a rating of #{r.rating}"
28
+ end
29
+
30
+ self.list_recipes_greeting
31
+
32
+ else
33
+ puts "Our app is having technical difficulties and we have no recipes :( Maybe you would like to here a 'joke' instead?"
34
+ @input = gets.strip
35
+
36
+ self.possible_commands
37
+ end
38
+ end
39
+
40
+ def self.list_recipes_greeting
41
+ self.line_break
42
+ puts "If you would like to see details on a recipe type the recipe's number. Don't forget to hear a 'joke' and of course you can type 'exit' or 'bye' when you need to go."
43
+
44
+ @input = gets.strip.downcase
45
+
46
+ if @input.to_i > 0
47
+ self.list_details
48
+ else
49
+ self.possible_commands
50
+ end
51
+
52
+ end
53
+
54
+ def self.list_details
55
+ self.line_break
56
+ recipe = TopRecipes::Recipe.top_recipes[@input.to_i - 1]
57
+ puts "---------- #{recipe.name} ----------"
58
+ self.line_break
59
+ puts "Recipe by #{recipe.author}, rating is #{recipe.rating}"
60
+ self.line_break
61
+ puts "---------- Ingredients: ----------"
62
+ self.list_ingredients(recipe)
63
+ self.line_break
64
+ puts "To find the direction go #{recipe.author}'s site at:"
65
+ puts "#{recipe.directions}"
66
+
67
+ self.again_or_close
68
+ end
69
+
70
+ def self.line_break
71
+ puts ""
72
+ 40.times{print "-"}
73
+ puts ""
74
+ puts ""
75
+ end
76
+
77
+ def self.list_ingredients(recipe)
78
+ recipe.ingredients.each.with_index(1) {|i, k| puts "#{k}. #{i}"}
79
+ end
80
+
81
+
82
+ def self.possible_commands
83
+ case @input.downcase
84
+ when "list recipes"
85
+ self.list_recipes
86
+ when "joke"
87
+ self.joke
88
+ when "exit"
89
+ self.exit_program
90
+ when "bye"
91
+ self.exit_program
92
+ else
93
+ self.no_match
94
+ end
95
+ end
96
+
97
+ def self.no_match
98
+ self.line_break
99
+ puts "Sorry! I do not understand what '#{@input}' is! Try one of these commands: 'list recipes', 'joke', 'exit'"
100
+
101
+ @input = gets.strip
102
+
103
+ self.possible_commands
104
+ end
105
+
106
+ def self.joke
107
+ self.line_break
108
+ puts "#{TopRecipes::Jokes.all.shuffle.first}"
109
+ self.again_or_close
110
+ end
111
+
112
+ def self.exit_program
113
+ puts "Bye! We hope to see you again soon!"
114
+ end
115
+
116
+ def self.again_or_close
117
+ self.line_break
118
+ puts "Would you like to do something like 'list recipes' or hear a 'joke'? If not, say 'bye'"
119
+
120
+
121
+ @input = gets.strip
122
+ self.possible_commands
123
+ end
124
+
125
+ end
@@ -0,0 +1,88 @@
1
+ class TopRecipes::Jokes
2
+
3
+ def self.all
4
+ [
5
+ "What if soy milk is just regular milk introducing itself in Spanish?",
6
+ "Q: What do you call cheese that isn’t yours? A: Nacho cheese!",
7
+ "Q: What did the baby corn say to its mom? A: Where’s my pop corn?",
8
+ "Q: Why couldn’t the sesame seed leave the gambling casino? A: Because he was on a roll.",
9
+ "Shroom walks in a bar, bartender says 'Hey you can’t drink here.' Mushroom says 'Why not, I’m a Fun-gi!'",
10
+ "Q: What do you call a fake noodle? A: An Impasta.",
11
+ "Q: Why did the tomato blush? A: Because it saw the salad dressing!",
12
+ "Q: Why don’t eggs tell jokes? A: They’d crack each other up!",
13
+ "Q. I tried to get into my house the other day, but I couldn’t. Wanna know why? A. Because I had gnocchi!",
14
+ "Q: What does a nosey pepper do? A: Gets jalapeno business!",
15
+ "Little Johnny's preschool class went on a field trip to the fire station. The firefighter giving the presentation held up a smoke detector and asked the class: 'Does anyone know what this is?'
16
+
17
+ Little Johnny's hand shot up and the firefighter called on him.
18
+
19
+ Little Johnny replied: 'That's how Mommy knows supper is ready!'",
20
+ "This 85 year old couple, having been married almost 60 years, had
21
+ died in a car crash. They had been in good health the last ten years
22
+ mainly due to her interest in health food, and exercise.
23
+ When they reached the pearly gates, St. Peter took them to their
24
+ mansion which was decked out with a beautiful kitchen and master
25
+ bath suite and Jacuzzi.
26
+ As they 'oohed and aahed' the old man asked Peter how much all
27
+ this was going to cost.
28
+ 'It's free,' Peter replied, 'this is Heaven.'
29
+ Next they went out back to survey the championship golf course
30
+ that the home backed up to. They would have golfing privileges
31
+ everyday and each week the course changed to a new one representing
32
+ the great golf courses on earth.
33
+ The old man asked, 'What are the green fees?'.
34
+ Peter's reply, 'This is heaven, you play for free.'
35
+ Next they went to the club house and saw the lavish buffet lunch
36
+ with the cuisines of the world laid out.
37
+ 'How much to eat?' asked the old man.
38
+ 'Don't you understand yet? This is heaven, it is free!' Peter replied
39
+ with some exasperation.
40
+ 'Well, where are the low fat and low cholesterol tables?' the old
41
+ man asked timidly.
42
+ Peter lectured, 'That's the best part...you can eat as much as you
43
+ like of whatever you like and you never get fat and you never get
44
+ sick. This is Heaven.'
45
+ With that the old man went into a fit of anger, throwing down his
46
+ hat and stomping on it, and shrieking wildly.
47
+ Peter and his wife both tried to calm him down, asking him what was
48
+ wrong. The old man looked at his wife and said, 'This is all your fault.
49
+ If it weren't for your blasted bran muffins, I could have been
50
+ here ten years ago!'",
51
+ "Q: Why don't men cook at home? A: No one's invented a steak that will fit in the toaster.",
52
+ "How do women define a 50/50 relationship?
53
+
54
+ We cook- They eat.
55
+ We clean. They dirt.
56
+ We iron. They wrinkle.",
57
+ "A preacher goes to a nursing home to meet an elderly parishioner. As he
58
+ is sitting there he notices this bowl of peanuts beside her bed and takes
59
+ one. As they talk, he can't help himself and eats one after another.
60
+ By the time they are through talking, the bowl is empty. He says,
61
+ 'Ma'am, I'm sorry, but I seem to have eaten all of your peanuts.'
62
+ 'That's okay,' she says. 'They would have just sat there. Without my
63
+ teeth, all I can do is suck the chocolate off and put them back.'",
64
+ "Did you hear about the new Chinese Cookbook being sold only at pet stores?
65
+
66
+ '101 Ways to Wok Your Dog'",
67
+ "A businessman had arranged an important formal dinner party at
68
+ his home where they were going to serve stuffed whole baked fish
69
+ as the main course. While the guests were eating the appetizer, the
70
+ cook came to the host and whispered 'Please come urgently to the
71
+ kitchen.' The host went to the kitchen where the cook explained that
72
+ while she was serving the starter, the cat ate a big chunk of the fish
73
+ which they were going to serve. The host said, 'Just fill the hole
74
+ with stuffing and turn the other side up, nobody will notice.'
75
+ The fish was served and when they were nearly finished eating, the
76
+ host was again called to the kitchen. The cook said, 'The cat is dead!'
77
+ The host rushed back to the dinner party and apologized, 'Something
78
+ was wrong with the fish and everyone must have their stomachs pumped
79
+ out at the hospital.' When they came back everything was still fine
80
+ and the host went to ask the cook, 'Where is the cat?'
81
+ 'Oh,' said the chef, 'The cat is still by the road where the
82
+ truck ran it down!'"
83
+ ]
84
+
85
+ end
86
+
87
+
88
+ end
@@ -0,0 +1,17 @@
1
+ class TopRecipes::Recipe
2
+
3
+ attr_accessor :rating, :url, :ingredients, :author, :directions
4
+ attr_reader :name
5
+
6
+ @@all = []
7
+
8
+ def initialize(name)
9
+ @name = name
10
+ @@all << self
11
+ end
12
+
13
+ def self.top_recipes
14
+ @@all
15
+ end
16
+
17
+ end
@@ -0,0 +1,27 @@
1
+ class TopRecipes::Scraper
2
+
3
+ def self.scrape_recipes_page(url)
4
+ Nokogiri::HTML(open(url))
5
+ end
6
+
7
+ def self.scrape_and_create_recipes_food2fork
8
+ self.scrape_recipes_page("http://food2fork.com/").css("div.img-polaroid").each do |r|
9
+ name = r.css("span.recipe-name").text.strip
10
+ recipe = TopRecipes::Recipe.new(name)
11
+ recipe.rating = r.css("span.badge-important").text.strip
12
+ recipe.url = "http://food2fork.com#{r.css("a.recipe-link").attribute("href").value.strip}"
13
+ recipe.author = r.css("span.publisher").text.strip
14
+
15
+ self.scrape_additional_info(recipe)
16
+ end
17
+ end
18
+
19
+ def self.scrape_additional_info(recipe)
20
+ raise error if !(recipe.is_a?(TopRecipes::Recipe))
21
+ site = self.scrape_recipes_page(recipe.url)
22
+
23
+ recipe.ingredients = site.css("div.span5 ul").text.strip.split("\n\t\t\t\t\n\t\t\t\t ")
24
+ recipe.directions = site.css("div.span5 a")[1].attribute("href").value
25
+ end
26
+
27
+ end
@@ -0,0 +1,3 @@
1
+ module TopRecipes
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'top_recipes/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "top-recipes"
8
+ spec.version = TopRecipes::VERSION
9
+ spec.authors = ["mxdavis"]
10
+ spec.email = ["md01@me.com"]
11
+ spec.summary = %q{Top trending recipes from http://food2fork.com/}
12
+ spec.description = %q{Top trending recipes from http://food2fork.com/}
13
+ spec.homepage = "https://github.com/mxdavis/recipes-from-food2fork-cli"
14
+
15
+ spec.files = `git ls-files`.split($\)
16
+ spec.executables = ["top-recipes"]
17
+ spec.require_paths = ["lib" "lib/top_recipes"]
18
+
19
+ spec.add_development_dependency "bundler", "~> 1.14"
20
+ spec.add_development_dependency "rake", "~> 10.0"
21
+ spec.add_development_dependency "pry"
22
+
23
+ spec.add_dependency "nokogiri"
24
+ end
metadata ADDED
@@ -0,0 +1,114 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: top-recipes
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - mxdavis
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-03-21 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: '1.14'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.14'
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: pry
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: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Top trending recipes from http://food2fork.com/
70
+ email:
71
+ - md01@me.com
72
+ executables:
73
+ - top-recipes
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - Gemfile
79
+ - README.md
80
+ - Rakefile
81
+ - bin/console
82
+ - bin/setup
83
+ - bin/top-recipes
84
+ - lib/top_recipes.rb
85
+ - lib/top_recipes/cli.rb
86
+ - lib/top_recipes/jokes.rb
87
+ - lib/top_recipes/recipe.rb
88
+ - lib/top_recipes/scraper.rb
89
+ - lib/top_recipes/version.rb
90
+ - top_recipes.gemspec
91
+ homepage: https://github.com/mxdavis/recipes-from-food2fork-cli
92
+ licenses: []
93
+ metadata: {}
94
+ post_install_message:
95
+ rdoc_options: []
96
+ require_paths:
97
+ - liblib/top_recipes
98
+ required_ruby_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ required_rubygems_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ requirements: []
109
+ rubyforge_project:
110
+ rubygems_version: 2.6.10
111
+ signing_key:
112
+ specification_version: 4
113
+ summary: Top trending recipes from http://food2fork.com/
114
+ test_files: []