cocktail_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 +7 -0
- data/bin/CocktailsRecipes +5 -0
- data/lib/cocktail_recipes.rb +12 -0
- data/lib/cocktail_recipes/cli.rb +54 -0
- data/lib/cocktail_recipes/recipes.rb +33 -0
- data/lib/cocktail_recipes/scraper.rb +41 -0
- data/lib/cocktail_recipes/version.rb +3 -0
- metadata +120 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 171ed699fcd2d09d1beec056a3420e97385024e8c1a5c9c34df78a24a27c8a73
|
|
4
|
+
data.tar.gz: 1b8c8bf8d963ae6a9318ae0c501143469c92c269cbeb031f8699f4dd1e2c7608
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 28e0e887a85a5aedee61d490fd32c8d0c35cde3cfa460a78430164a9af503ece2e2ed8710f189d78a0bc66c4db117f15dd79cfeb1a4107d5d4ea2a83eceddd62
|
|
7
|
+
data.tar.gz: 5434498fbc9404c522e248ba693aafb0f37a4ba95e6bb732500bc2f5daa04f551e95f3b3f4c0b6f0b29e9b8dab7737b6ad66bc7eac27e77e70671a95d9b94ce8
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
require 'pry'
|
|
2
|
+
require 'nokogiri'
|
|
3
|
+
require 'open-uri'
|
|
4
|
+
|
|
5
|
+
module CocktailRecipes
|
|
6
|
+
# Your code goes here...
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
require_relative "./cocktail_recipes/recipes"
|
|
10
|
+
require_relative "./cocktail_recipes/scraper"
|
|
11
|
+
require_relative "./cocktail_recipes/version"
|
|
12
|
+
require_relative "./cocktail_recipes/cli"
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
class CocktailRecipes::Cli
|
|
2
|
+
|
|
3
|
+
def welcome
|
|
4
|
+
CocktailRecipes::Scraper.new("https://www.foodandwine.com/cocktail-recipes").scrape
|
|
5
|
+
puts "Hi, Welcome to Reinvented Classic Cocktails"
|
|
6
|
+
main_menu
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def main_menu
|
|
10
|
+
puts "Here is a list of all of our cocktails:"
|
|
11
|
+
display_cocktails_list
|
|
12
|
+
puts "Type the number of the cocktail you would like to learn."
|
|
13
|
+
input = gets.strip.to_i
|
|
14
|
+
if (1..CocktailRecipes::Recipes.all.length).include?(input)
|
|
15
|
+
puts CocktailRecipes::Recipes.all[input-1].name.upcase
|
|
16
|
+
puts ""
|
|
17
|
+
puts "Ingredients"
|
|
18
|
+
puts CocktailRecipes::Recipes.all[input-1].ingredients
|
|
19
|
+
puts ""
|
|
20
|
+
puts "Instructions"
|
|
21
|
+
puts CocktailRecipes::Recipes.all[input-1].instructions
|
|
22
|
+
puts ""
|
|
23
|
+
menu_options
|
|
24
|
+
else
|
|
25
|
+
invalid
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def menu_options
|
|
30
|
+
puts "Would you like to see another recipe?"
|
|
31
|
+
puts "Type (Yes or No) "
|
|
32
|
+
input = gets.strip.downcase
|
|
33
|
+
input == "yes" ? main_menu : good_bye
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def good_bye
|
|
37
|
+
puts "Thank you for your visit."
|
|
38
|
+
puts "You're welcome to come back anytime!"
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def invalid
|
|
42
|
+
puts "Im sorry. This is not an option."
|
|
43
|
+
puts "Please try againg."
|
|
44
|
+
main_menu
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def display_cocktails_list
|
|
48
|
+
CocktailRecipes::Recipes.all.each.with_index do |c, i|
|
|
49
|
+
puts "#{i+1}. #{c.name}"
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
end
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
class CocktailRecipes::Recipes
|
|
2
|
+
attr_accessor :name, :ingredients, :instructions , :url
|
|
3
|
+
|
|
4
|
+
@@all = []
|
|
5
|
+
|
|
6
|
+
def initialize(hash)
|
|
7
|
+
hash.each do |key, value|
|
|
8
|
+
self.send("#{key}=",value)
|
|
9
|
+
end
|
|
10
|
+
@ingredients = []
|
|
11
|
+
@instructions = instructions
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def self.all
|
|
15
|
+
@@all
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def save
|
|
19
|
+
self.class.all.push(self)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def self.create(hash)
|
|
23
|
+
recipe = self.new(hash)
|
|
24
|
+
recipe.save
|
|
25
|
+
recipe
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def self.create_from_array(array)
|
|
29
|
+
array.each do |hash|
|
|
30
|
+
self.create(hash)
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
class CocktailRecipes::Scraper
|
|
2
|
+
attr_accessor :cocktails_page
|
|
3
|
+
|
|
4
|
+
def initialize(url)
|
|
5
|
+
self.cocktails_page = url
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def scrape_homepage
|
|
9
|
+
recipes = []
|
|
10
|
+
site= Nokogiri::HTML(open(self.cocktails_page))
|
|
11
|
+
site.css("li.rsw-teaser").each do |li|
|
|
12
|
+
recipe_hash = {}
|
|
13
|
+
recipe_hash[:name]= li.css("h3").text
|
|
14
|
+
recipe_hash[:url]= "https://www.foodandwine.com#{li.css("a").attribute('href').text}"
|
|
15
|
+
recipes.push(recipe_hash)
|
|
16
|
+
end
|
|
17
|
+
CocktailRecipes::Recipes.create_from_array(recipes)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def scrape_profile
|
|
21
|
+
CocktailRecipes::Recipes.all.each do |recipe|
|
|
22
|
+
site= Nokogiri::HTML(open(recipe.url))
|
|
23
|
+
hash = {}
|
|
24
|
+
|
|
25
|
+
ingrds = site.css('div.ingredients').text
|
|
26
|
+
if ingrds.count("\r") != 0
|
|
27
|
+
recipe.ingredients = ingrds.gsub("\r", "_").split.join("\n").gsub("\n", " ").split("_").map {|string| string.split.join(" ") }
|
|
28
|
+
else
|
|
29
|
+
recipe.ingredients = ingrds.split("\n").map { |string| string.gsub(/\s+(?=\d)/, "") }.delete_if{|str| str[0] == " "}.reject { |c| c.empty? }
|
|
30
|
+
end
|
|
31
|
+
recipe.instructions = site.css('div.step p').text
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def scrape
|
|
37
|
+
scrape_homepage
|
|
38
|
+
scrape_profile
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: cocktail_recipes
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Nathalie Santana
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2018-09-05 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.10'
|
|
20
|
+
type: :development
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '1.10'
|
|
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: rspec
|
|
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: :development
|
|
63
|
+
prerelease: false
|
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - "~>"
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: '0'
|
|
69
|
+
- !ruby/object:Gem::Dependency
|
|
70
|
+
name: pry
|
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
|
72
|
+
requirements:
|
|
73
|
+
- - "~>"
|
|
74
|
+
- !ruby/object:Gem::Version
|
|
75
|
+
version: '0'
|
|
76
|
+
type: :development
|
|
77
|
+
prerelease: false
|
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
79
|
+
requirements:
|
|
80
|
+
- - "~>"
|
|
81
|
+
- !ruby/object:Gem::Version
|
|
82
|
+
version: '0'
|
|
83
|
+
description: Displays a list of Classic cocktails recipes with a twist
|
|
84
|
+
email: nathalie.scruz@gmail.com
|
|
85
|
+
executables:
|
|
86
|
+
- CocktailsRecipes
|
|
87
|
+
extensions: []
|
|
88
|
+
extra_rdoc_files: []
|
|
89
|
+
files:
|
|
90
|
+
- bin/CocktailsRecipes
|
|
91
|
+
- lib/cocktail_recipes.rb
|
|
92
|
+
- lib/cocktail_recipes/cli.rb
|
|
93
|
+
- lib/cocktail_recipes/recipes.rb
|
|
94
|
+
- lib/cocktail_recipes/scraper.rb
|
|
95
|
+
- lib/cocktail_recipes/version.rb
|
|
96
|
+
homepage:
|
|
97
|
+
licenses:
|
|
98
|
+
- MIT
|
|
99
|
+
metadata: {}
|
|
100
|
+
post_install_message:
|
|
101
|
+
rdoc_options: []
|
|
102
|
+
require_paths:
|
|
103
|
+
- lib
|
|
104
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
105
|
+
requirements:
|
|
106
|
+
- - ">="
|
|
107
|
+
- !ruby/object:Gem::Version
|
|
108
|
+
version: '0'
|
|
109
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
110
|
+
requirements:
|
|
111
|
+
- - ">="
|
|
112
|
+
- !ruby/object:Gem::Version
|
|
113
|
+
version: '0'
|
|
114
|
+
requirements: []
|
|
115
|
+
rubyforge_project:
|
|
116
|
+
rubygems_version: 2.7.7
|
|
117
|
+
signing_key:
|
|
118
|
+
specification_version: 4
|
|
119
|
+
summary: Reinvented Classic Cocktails
|
|
120
|
+
test_files: []
|