Fast_Food_Nutrition 0.2.1 → 1.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/bin/ff_nutrition +1 -1
- data/lib/Fast_Food_Nutrition.rb +3 -0
- data/lib/Fast_Food_Nutrition/category.rb +2 -10
- data/lib/Fast_Food_Nutrition/cli.rb +12 -11
- data/lib/Fast_Food_Nutrition/items.rb +2 -10
- data/lib/Fast_Food_Nutrition/restaurant.rb +2 -10
- data/lib/Fast_Food_Nutrition/scraper.rb +20 -62
- data/lib/Fast_Food_Nutrition/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 01acfb8c515ee8ae9719436e450183cd14b6e438c8fe17955822fabaa0fa738f
|
4
|
+
data.tar.gz: cf9f4250606c3eccbe6287cf32c20ed29a9e5c5639984516678cfd20560d1947
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4d53b04cbf55d642d24b4446fed918d4c712690be38ffc9fa90046b77395c1623a0c80ed9b61a9163a3644776ba8fb07afa819c2ae907409fe32f7e11c055ea1
|
7
|
+
data.tar.gz: 599b8089518e877f46aad9efd6b265aa164a511248f39351d8feb620db7d741f5e3099addf738dbc79e2dd862e56657a3d05095ee871c17bb19c7972eb43a375
|
data/Gemfile.lock
CHANGED
data/bin/ff_nutrition
CHANGED
data/lib/Fast_Food_Nutrition.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
class Category
|
2
|
-
attr_accessor :name
|
1
|
+
class FastFoodNutrition::Category
|
2
|
+
attr_accessor :name, :items
|
3
3
|
@@all = []
|
4
4
|
|
5
5
|
def initialize(name)
|
@@ -11,12 +11,4 @@ class Category
|
|
11
11
|
@@all
|
12
12
|
end
|
13
13
|
|
14
|
-
def items=(item_array)
|
15
|
-
@items = item_array
|
16
|
-
end
|
17
|
-
|
18
|
-
def items
|
19
|
-
@items
|
20
|
-
end
|
21
|
-
|
22
14
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
class Welcome
|
1
|
+
class FastFoodNutrition::Welcome
|
2
2
|
|
3
3
|
def intro
|
4
4
|
puts "Welcome To The Fast Food Nutrition Finder"
|
@@ -8,37 +8,38 @@ class Welcome
|
|
8
8
|
def list_restaurants
|
9
9
|
selection = 0
|
10
10
|
puts "\nPlease select a Restaurant by number:"
|
11
|
-
Scraper.new.scrape_site_for_restaurants("http://www.nutrition-charts.com/") if Restaurant.all.size == 0
|
12
|
-
Restaurant.all.each_with_index {|restaurant, i| puts "#{i + 1}: #{restaurant.name}"}
|
13
|
-
|
14
|
-
|
15
|
-
|
11
|
+
FastFoodNutrition::Scraper.new.scrape_site_for_restaurants("http://www.nutrition-charts.com/") if FastFoodNutrition::Restaurant.all.size == 0
|
12
|
+
FastFoodNutrition::Restaurant.all.each_with_index {|restaurant, i| puts "#{i + 1}: #{restaurant.name}"}
|
13
|
+
# consider #between?
|
14
|
+
selection = gets.strip.to_i until selection.between?(1, FastFoodNutrition::Restaurant.all.size)
|
15
|
+
puts "\nYou selected #{FastFoodNutrition::Restaurant.all[selection - 1].name}"
|
16
|
+
select_category(FastFoodNutrition::Restaurant.all[selection - 1])
|
16
17
|
end
|
17
18
|
|
18
19
|
def select_category(restaurant)
|
19
|
-
restaurant.categories = Scraper.new.scrape_restaurant_categories(restaurant) if !restaurant.categories
|
20
|
+
restaurant.categories = FastFoodNutrition::Scraper.new.scrape_restaurant_categories(restaurant) if !restaurant.categories
|
20
21
|
selection = 0
|
21
22
|
puts "\nPlease select a Category of Menu Items:"
|
22
23
|
restaurant.categories.each_with_index {|category, i| puts "#{i + 1}: #{category.name}"}
|
23
|
-
selection = gets.strip.to_i until selection
|
24
|
+
selection = gets.strip.to_i until selection.between?(1, restaurant.categories.size)
|
24
25
|
puts "\nYou selected #{restaurant.categories[selection - 1].name}"
|
25
26
|
select_item(restaurant, selection - 1)
|
26
27
|
end
|
27
28
|
|
28
29
|
def select_item(restaurant, cat_picked)
|
29
|
-
restaurant.categories[cat_picked].items = Scraper.new.scrape_category_items(restaurant, cat_picked) if !restaurant.categories[cat_picked].items
|
30
|
+
restaurant.categories[cat_picked].items = FastFoodNutrition::Scraper.new.scrape_category_items(restaurant, cat_picked) if !restaurant.categories[cat_picked].items
|
30
31
|
selection = 0
|
31
32
|
puts "\nPlease select an item:"
|
32
33
|
restaurant.categories[cat_picked].items.each_with_index do |item, i|
|
33
34
|
puts "#{i + 1}: #{item.name}"
|
34
35
|
end
|
35
|
-
selection = gets.strip.to_i until selection
|
36
|
+
selection = gets.strip.to_i until selection.between?(1, restaurant.categories[cat_picked].items.size)
|
36
37
|
puts "\nYou selected #{restaurant.categories[cat_picked].items[selection - 1].name}"
|
37
38
|
get_nutrition(restaurant, cat_picked, selection - 1)
|
38
39
|
end
|
39
40
|
|
40
41
|
def get_nutrition(restaurant, cat_picked, item_picked)
|
41
|
-
restaurant.categories[cat_picked].items[item_picked].nutrition = Scraper.new.scrape_nutrition_info(restaurant, cat_picked, item_picked) if !restaurant.categories[cat_picked].items[item_picked].nutrition
|
42
|
+
restaurant.categories[cat_picked].items[item_picked].nutrition = FastFoodNutrition::Scraper.new.scrape_nutrition_info(restaurant, cat_picked, item_picked) if !restaurant.categories[cat_picked].items[item_picked].nutrition
|
42
43
|
puts "\nHere is the nutrition information for #{restaurant.categories[cat_picked].items[item_picked].name}:"
|
43
44
|
restaurant.categories[cat_picked].items[item_picked].nutrition.each do |item|
|
44
45
|
puts " #{item[0]}: #{item[1]}"
|
@@ -1,5 +1,5 @@
|
|
1
|
-
class Item
|
2
|
-
attr_accessor :name
|
1
|
+
class FastFoodNutrition::Item
|
2
|
+
attr_accessor :name, :nutrition
|
3
3
|
@@all = []
|
4
4
|
|
5
5
|
def initialize(name)
|
@@ -10,12 +10,4 @@ class Item
|
|
10
10
|
@@all
|
11
11
|
end
|
12
12
|
|
13
|
-
def nutrition=(nutrition_array)
|
14
|
-
@nutrition = nutrition_array
|
15
|
-
end
|
16
|
-
|
17
|
-
def nutrition
|
18
|
-
@nutrition
|
19
|
-
end
|
20
|
-
|
21
13
|
end
|
@@ -1,5 +1,5 @@
|
|
1
|
-
class Restaurant
|
2
|
-
attr_accessor :name, :url
|
1
|
+
class FastFoodNutrition::Restaurant
|
2
|
+
attr_accessor :name, :url, :categories
|
3
3
|
@@all = []
|
4
4
|
def initialize(name, url)
|
5
5
|
@name = name
|
@@ -11,14 +11,6 @@ class Restaurant
|
|
11
11
|
@@all
|
12
12
|
end
|
13
13
|
|
14
|
-
def categories=(category_array)
|
15
|
-
@categories = category_array
|
16
|
-
end
|
17
|
-
|
18
|
-
def categories
|
19
|
-
@categories
|
20
|
-
end
|
21
|
-
|
22
14
|
def self.find_restaurant_by_name(name)
|
23
15
|
restaurant = ""
|
24
16
|
self.all.each do |location|
|
@@ -1,21 +1,11 @@
|
|
1
|
-
|
2
|
-
require 'Nokogiri'
|
3
|
-
require 'open-uri'
|
4
|
-
|
5
|
-
class Scraper
|
1
|
+
class FastFoodNutrition::Scraper
|
6
2
|
def scrape_site_for_restaurants(url)
|
7
3
|
site = Nokogiri::HTML(open(url))
|
8
4
|
site = site.css("div.entry-content table tbody tr")
|
9
5
|
site.each do |restaurant|
|
10
|
-
Restaurant.new(restaurant.css("td")[1].css("a").text.strip, "http://www.nutrition-charts.com/#{restaurant.css("td")[1].css("a").attribute("href").value}")
|
11
|
-
Restaurant.new(restaurant.css("td")[3].css("a").text.strip, "http://www.nutrition-charts.com/#{restaurant.css("td")[3].css("a").attribute("href").value}")
|
6
|
+
FastFoodNutrition::Restaurant.new(restaurant.css("td")[1].css("a").text.strip, "http://www.nutrition-charts.com/#{restaurant.css("td")[1].css("a").attribute("href").value}")
|
7
|
+
FastFoodNutrition::Restaurant.new(restaurant.css("td")[3].css("a").text.strip, "http://www.nutrition-charts.com/#{restaurant.css("td")[3].css("a").attribute("href").value}")
|
12
8
|
end
|
13
|
-
# Restaurant.all.each do |location|
|
14
|
-
# puts "#{location.name}"
|
15
|
-
# location.categories = scrape_restaurant_categories(location)
|
16
|
-
# #binding.pry
|
17
|
-
# end
|
18
|
-
# binding.pry
|
19
9
|
end
|
20
10
|
|
21
11
|
def scrape_restaurant_categories(location)
|
@@ -23,31 +13,17 @@ class Scraper
|
|
23
13
|
url = "#{location.url}"
|
24
14
|
site = Nokogiri::HTML(open(url))
|
25
15
|
case location.name
|
26
|
-
when "Burger King"
|
27
|
-
site = site.css("div table tbody td h3")
|
28
|
-
site.each do |item|
|
29
|
-
category = Category.new(item.text)
|
30
|
-
category_list << category
|
31
|
-
end
|
32
|
-
category_list
|
33
|
-
when "Wendys"
|
16
|
+
when "Burger King", "Wendys", "Buffalo Wild Wings", "McDonalds"
|
34
17
|
site = site.css("div table tbody td h3")
|
35
18
|
site.each do |item|
|
36
|
-
category =
|
37
|
-
category_list << category
|
38
|
-
end
|
39
|
-
category_list
|
40
|
-
when "Buffalo Wild Wings"
|
41
|
-
site = site.css("div table tbody td h3")
|
42
|
-
site.each do |item|
|
43
|
-
category = Category.new(item.text)
|
19
|
+
category = FastFoodNutrition::Category.new(item.text)
|
44
20
|
category_list << category
|
45
21
|
end
|
46
22
|
category_list
|
47
23
|
when "Pizza Hut"
|
48
24
|
site = site.css("div table tbody td strong")
|
49
25
|
site.each do |item|
|
50
|
-
category = Category.new(item.text)
|
26
|
+
category = FastFoodNutrition::Category.new(item.text)
|
51
27
|
category_list << category
|
52
28
|
end
|
53
29
|
category_list
|
@@ -55,15 +31,14 @@ class Scraper
|
|
55
31
|
site = site.css("div table tbody")
|
56
32
|
site = site.css("tr.rowheader")
|
57
33
|
site.each do |item|
|
58
|
-
category = Category.new(item.css("td")[0].text)
|
34
|
+
category = FastFoodNutrition::Category.new(item.css("td")[0].text)
|
59
35
|
category_list << category
|
60
36
|
end
|
61
37
|
category_list
|
62
|
-
when "Baja Fresh"
|
38
|
+
when "Baja Fresh"
|
63
39
|
site = site.css("div table tbody tr")
|
64
40
|
site.each do |item|
|
65
|
-
item.to_s.include?("<th>") ? category = Category.new(item.css("th")[0].text) : ""
|
66
|
-
#category = Category.new(item.css("th")[0].text)
|
41
|
+
item.to_s.include?("<th>") ? category = FastFoodNutrition::Category.new(item.css("th")[0].text) : ""
|
67
42
|
if category
|
68
43
|
category_list << category
|
69
44
|
end
|
@@ -71,11 +46,11 @@ class Scraper
|
|
71
46
|
category_list
|
72
47
|
else
|
73
48
|
site = site.css("div table tbody")
|
74
|
-
category = Category.new(site[0].css("tr")[0].css("th")[0].text)
|
49
|
+
category = FastFoodNutrition::Category.new(site[0].css("tr")[0].css("th")[0].text)
|
75
50
|
category_list << category
|
76
51
|
site = site.css("tr.rowheader")
|
77
52
|
site.each do |item|
|
78
|
-
category = Category.new(item.css("th")[0].text)
|
53
|
+
category = FastFoodNutrition::Category.new(item.css("th")[0].text)
|
79
54
|
category_list << category
|
80
55
|
end
|
81
56
|
category_list
|
@@ -87,24 +62,7 @@ class Scraper
|
|
87
62
|
url = "#{restaurant.url}"
|
88
63
|
site = Nokogiri::HTML(open(url))
|
89
64
|
case restaurant.name
|
90
|
-
when "Burger King"
|
91
|
-
site = site.css("div table tbody tr")
|
92
|
-
site.each do |item|
|
93
|
-
if item.to_s.include?("<h3>")
|
94
|
-
if item.css("h3")[0].text == restaurant.categories[category].name
|
95
|
-
next_item = item.next_element
|
96
|
-
begin
|
97
|
-
if next_item.to_s.include?("<td>") && !next_item.to_s.include?("<span") && !next_item.to_s.include?("header")
|
98
|
-
item_list << Item.new(next_item.css("td")[0].text)
|
99
|
-
end
|
100
|
-
next_item = next_item.next_element
|
101
|
-
next_item == nil ? next_item = "<h3>" : next_item
|
102
|
-
end while !next_item.to_s.include?("<h3>")
|
103
|
-
end
|
104
|
-
end
|
105
|
-
end
|
106
|
-
item_list
|
107
|
-
when "Wendys"
|
65
|
+
when "Burger King", "Wendys", "McDonalds"
|
108
66
|
site = site.css("div table tbody tr")
|
109
67
|
site.each do |item|
|
110
68
|
if item.to_s.include?("<h3>")
|
@@ -112,7 +70,7 @@ class Scraper
|
|
112
70
|
next_item = item.next_element
|
113
71
|
begin
|
114
72
|
if next_item.to_s.include?("<td>") && !next_item.to_s.include?("<span") && !next_item.to_s.include?("header")
|
115
|
-
item_list << Item.new(next_item.css("td")[0].text)
|
73
|
+
item_list << FastFoodNutrition::Item.new(next_item.css("td")[0].text)
|
116
74
|
end
|
117
75
|
next_item = next_item.next_element
|
118
76
|
next_item == nil ? next_item = "<h3>" : next_item
|
@@ -129,7 +87,7 @@ class Scraper
|
|
129
87
|
next_item = item.next_element
|
130
88
|
begin
|
131
89
|
if next_item.to_s.include?("<td>") && !next_item.to_s.include?("<span") && !next_item.to_s.include?("header") && next_item.css("td")[0].text != " "
|
132
|
-
item_list << Item.new(next_item.css("td")[0].text)
|
90
|
+
item_list << FastFoodNutrition::Item.new(next_item.css("td")[0].text)
|
133
91
|
end
|
134
92
|
next_item = next_item.next_element
|
135
93
|
next_item == nil ? next_item = "<h3>" : next_item
|
@@ -145,7 +103,7 @@ class Scraper
|
|
145
103
|
if item.css("strong")[0].text == restaurant.categories[category].name
|
146
104
|
next_item = item.next_element
|
147
105
|
begin
|
148
|
-
item_list << Item.new(next_item.css("td")[0].text) if !next_item.to_s.include?("<span")
|
106
|
+
item_list << FastFoodNutrition::Item.new(next_item.css("td")[0].text) if !next_item.to_s.include?("<span")
|
149
107
|
next_item = next_item.next_element
|
150
108
|
next_item == nil ? next_item = "<strong>" : next_item
|
151
109
|
end while !next_item.to_s.include?("<strong>")
|
@@ -160,7 +118,7 @@ class Scraper
|
|
160
118
|
if item.css("td")[0].text == restaurant.categories[category].name
|
161
119
|
next_item = item.next_element
|
162
120
|
begin
|
163
|
-
item_list << Item.new(next_item.css("td")[0].text) if !next_item.to_s.include?("<span")
|
121
|
+
item_list << FastFoodNutrition::Item.new(next_item.css("td")[0].text) if !next_item.to_s.include?("<span")
|
164
122
|
next_item = next_item.next_element
|
165
123
|
next_item == nil ? next_item = "<rowheader>" : next_item
|
166
124
|
end while !next_item.to_s.include?("rowheader")
|
@@ -175,7 +133,7 @@ class Scraper
|
|
175
133
|
if item.css("th")[0].text == restaurant.categories[category].name
|
176
134
|
next_item = item.next_element
|
177
135
|
begin
|
178
|
-
item_list << Item.new(next_item.css("td")[0].text) if !next_item.to_s.include?("<span")
|
136
|
+
item_list << FastFoodNutrition::Item.new(next_item.css("td")[0].text) if !next_item.to_s.include?("<span")
|
179
137
|
next_item = next_item.next_element
|
180
138
|
next_item == nil ? next_item = "<th>" : next_item
|
181
139
|
end while !next_item.to_s.include?("<th>")
|
@@ -205,7 +163,7 @@ class Scraper
|
|
205
163
|
end
|
206
164
|
end
|
207
165
|
end
|
208
|
-
end
|
166
|
+
end
|
209
167
|
nutrition_list.shift
|
210
168
|
nutrition_list
|
211
169
|
when "Pizza Hut"
|
@@ -222,7 +180,7 @@ class Scraper
|
|
222
180
|
end
|
223
181
|
end
|
224
182
|
end
|
225
|
-
end
|
183
|
+
end
|
226
184
|
nutrition_list.shift
|
227
185
|
nutrition_list
|
228
186
|
else
|
@@ -239,7 +197,7 @@ class Scraper
|
|
239
197
|
end
|
240
198
|
end
|
241
199
|
end
|
242
|
-
end
|
200
|
+
end
|
243
201
|
nutrition_list.shift
|
244
202
|
nutrition_list
|
245
203
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: Fast_Food_Nutrition
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Hernandez
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-06-
|
11
|
+
date: 2018-06-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: open_uri_redirections
|