Fast_Food_Nutrition 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 +4 -4
- data/Gemfile.lock +1 -1
- data/lib/Fast_Food_Nutrition/category.rb +22 -0
- data/lib/Fast_Food_Nutrition/cli.rb +22 -21
- data/lib/Fast_Food_Nutrition/items.rb +21 -0
- data/lib/Fast_Food_Nutrition/restaurant.rb +32 -0
- data/lib/Fast_Food_Nutrition/scraper.rb +55 -39
- data/lib/Fast_Food_Nutrition/version.rb +1 -1
- data/lib/Fast_Food_Nutrition.rb +3 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9f360021fb48ae1d58ca22ca8d7d7c684c014094558645982ffde43dea5e59d4
|
4
|
+
data.tar.gz: 95abd536119b466e7f68df58ed760fec36d64080c3431ec2a803138ebcbf7764
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b584351e44e9e48b9bf9295aff2f77a07af9dcd5ac242ce6520875c2b41c206a8a1e1f4427daa44cbb2cebab1ac39664ac4b8f2276f7cdc4c40a79a49cdc1005
|
7
|
+
data.tar.gz: 2a1c975fa1ecdf6c02c022d4907e3b01db386a0ea7db29b15a2b3015000305267168e0bd363085a47f1ef87e4a2c77c19e077cc535f1b282823af3ece47c0308
|
data/Gemfile.lock
CHANGED
@@ -0,0 +1,22 @@
|
|
1
|
+
class Category
|
2
|
+
attr_accessor :name
|
3
|
+
@@all = []
|
4
|
+
|
5
|
+
def initialize(name)
|
6
|
+
@name = name
|
7
|
+
@@all << self
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.all
|
11
|
+
@@all
|
12
|
+
end
|
13
|
+
|
14
|
+
def items=(item_array)
|
15
|
+
@items = item_array
|
16
|
+
end
|
17
|
+
|
18
|
+
def items
|
19
|
+
@items
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
@@ -8,38 +8,39 @@ class Welcome
|
|
8
8
|
def list_restaurants
|
9
9
|
selection = 0
|
10
10
|
puts "\nPlease select a Restaurant by number:"
|
11
|
-
|
12
|
-
|
13
|
-
selection = gets.strip.to_i until selection > 0 && selection <=
|
14
|
-
puts "\nYou selected #{
|
15
|
-
select_category(
|
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
|
+
selection = gets.strip.to_i until selection > 0 && selection <= Restaurant.all.size
|
14
|
+
puts "\nYou selected #{Restaurant.all[selection - 1].name}"
|
15
|
+
select_category(Restaurant.all[selection - 1])
|
16
16
|
end
|
17
17
|
|
18
|
-
def select_category(
|
18
|
+
def select_category(restaurant)
|
19
|
+
restaurant.categories = Scraper.new.scrape_restaurant_categories(restaurant) if !restaurant.categories
|
19
20
|
selection = 0
|
20
21
|
puts "\nPlease select a Category of Menu Items:"
|
21
|
-
categories.each_with_index {|category, i| puts "#{i + 1}: #{category}"}
|
22
|
-
selection = gets.strip.to_i until selection > 0 && selection <= categories.
|
23
|
-
puts "\nYou selected #{categories[selection - 1]}"
|
24
|
-
select_item(
|
22
|
+
restaurant.categories.each_with_index {|category, i| puts "#{i + 1}: #{category.name}"}
|
23
|
+
selection = gets.strip.to_i until selection > 0 && selection <= restaurant.categories.size
|
24
|
+
puts "\nYou selected #{restaurant.categories[selection - 1].name}"
|
25
|
+
select_item(restaurant, selection - 1)
|
25
26
|
end
|
26
27
|
|
27
|
-
def select_item(
|
28
|
-
|
28
|
+
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
|
29
30
|
selection = 0
|
30
31
|
puts "\nPlease select an item:"
|
31
|
-
|
32
|
-
puts "#{i}: #{item}"
|
33
|
-
i += 1
|
32
|
+
restaurant.categories[cat_picked].items.each_with_index do |item, i|
|
33
|
+
puts "#{i + 1}: #{item.name}"
|
34
34
|
end
|
35
|
-
selection = gets.strip.to_i until selection > 0 && selection <=
|
36
|
-
puts "\nYou selected #{
|
37
|
-
get_nutrition(
|
35
|
+
selection = gets.strip.to_i until selection > 0 && selection <= restaurant.categories[cat_picked].items.size
|
36
|
+
puts "\nYou selected #{restaurant.categories[cat_picked].items[selection - 1].name}"
|
37
|
+
get_nutrition(restaurant, cat_picked, selection - 1)
|
38
38
|
end
|
39
39
|
|
40
|
-
def get_nutrition(
|
41
|
-
|
42
|
-
|
40
|
+
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
|
+
puts "\nHere is the nutrition information for #{restaurant.categories[cat_picked].items[item_picked].name}:"
|
43
|
+
restaurant.categories[cat_picked].items[item_picked].nutrition.each do |item|
|
43
44
|
puts " #{item[0]}: #{item[1]}"
|
44
45
|
end
|
45
46
|
continue?
|
@@ -0,0 +1,21 @@
|
|
1
|
+
class Item
|
2
|
+
attr_accessor :name
|
3
|
+
@@all = []
|
4
|
+
|
5
|
+
def initialize(name)
|
6
|
+
@name = name
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.all
|
10
|
+
@@all
|
11
|
+
end
|
12
|
+
|
13
|
+
def nutrition=(nutrition_array)
|
14
|
+
@nutrition = nutrition_array
|
15
|
+
end
|
16
|
+
|
17
|
+
def nutrition
|
18
|
+
@nutrition
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
class Restaurant
|
2
|
+
attr_accessor :name, :url
|
3
|
+
@@all = []
|
4
|
+
def initialize(name, url)
|
5
|
+
@name = name
|
6
|
+
@url = url
|
7
|
+
@@all << self
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.all
|
11
|
+
@@all
|
12
|
+
end
|
13
|
+
|
14
|
+
def categories=(category_array)
|
15
|
+
@categories = category_array
|
16
|
+
end
|
17
|
+
|
18
|
+
def categories
|
19
|
+
@categories
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.find_restaurant_by_name(name)
|
23
|
+
restaurant = ""
|
24
|
+
self.all.each do |location|
|
25
|
+
if name == location.name
|
26
|
+
restaurant = location
|
27
|
+
end
|
28
|
+
end
|
29
|
+
restaurant
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
@@ -1,85 +1,101 @@
|
|
1
|
-
require 'nokogiri'
|
2
|
-
require 'open-uri'
|
3
1
|
require 'pry'
|
2
|
+
require 'Nokogiri'
|
3
|
+
require 'open-uri'
|
4
4
|
|
5
5
|
class Scraper
|
6
6
|
def scrape_site_for_restaurants(url)
|
7
|
-
restaurants = []
|
8
7
|
site = Nokogiri::HTML(open(url))
|
9
8
|
site = site.css("div.entry-content table tbody tr")
|
10
9
|
site.each do |restaurant|
|
11
|
-
|
12
|
-
|
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}")
|
13
12
|
end
|
14
|
-
|
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
|
15
19
|
end
|
16
20
|
|
17
|
-
def scrape_restaurant_categories(
|
21
|
+
def scrape_restaurant_categories(location)
|
18
22
|
category_list = []
|
19
|
-
url = "
|
23
|
+
url = "#{location.url}"
|
20
24
|
site = Nokogiri::HTML(open(url))
|
21
|
-
case
|
25
|
+
case location.name
|
22
26
|
when "Burger King"
|
23
27
|
site = site.css("div table tbody td h3")
|
24
28
|
site.each do |item|
|
25
|
-
|
29
|
+
category = Category.new(item.text)
|
30
|
+
category_list << category
|
26
31
|
end
|
27
32
|
category_list
|
28
33
|
when "Wendys"
|
29
34
|
site = site.css("div table tbody td h3")
|
30
35
|
site.each do |item|
|
31
|
-
|
36
|
+
category = Category.new(item.text)
|
37
|
+
category_list << category
|
32
38
|
end
|
33
39
|
category_list
|
34
40
|
when "Buffalo Wild Wings"
|
35
41
|
site = site.css("div table tbody td h3")
|
36
42
|
site.each do |item|
|
37
|
-
|
43
|
+
category = Category.new(item.text)
|
44
|
+
category_list << category
|
38
45
|
end
|
39
46
|
category_list
|
40
47
|
when "Pizza Hut"
|
41
48
|
site = site.css("div table tbody td strong")
|
42
49
|
site.each do |item|
|
43
|
-
|
50
|
+
category = Category.new(item.text)
|
51
|
+
category_list << category
|
44
52
|
end
|
45
53
|
category_list
|
46
54
|
when "Applebees"
|
47
55
|
site = site.css("div table tbody")
|
48
56
|
site = site.css("tr.rowheader")
|
49
57
|
site.each do |item|
|
50
|
-
|
58
|
+
category = Category.new(item.css("td")[0].text)
|
59
|
+
category_list << category
|
51
60
|
end
|
52
61
|
category_list
|
53
|
-
when "Baja Fresh"
|
62
|
+
when "Baja Fresh" #Still having issues with this one
|
54
63
|
site = site.css("div table tbody tr")
|
55
64
|
site.each do |item|
|
56
|
-
item.to_s.include?("<th>") ?
|
65
|
+
item.to_s.include?("<th>") ? category = Category.new(item.css("th")[0].text) : ""
|
66
|
+
#category = Category.new(item.css("th")[0].text)
|
67
|
+
if category
|
68
|
+
category_list << category
|
69
|
+
end
|
57
70
|
end
|
58
71
|
category_list
|
59
72
|
else
|
60
73
|
site = site.css("div table tbody")
|
61
|
-
|
74
|
+
category = Category.new(site[0].css("tr")[0].css("th")[0].text)
|
75
|
+
category_list << category
|
62
76
|
site = site.css("tr.rowheader")
|
63
77
|
site.each do |item|
|
64
|
-
|
78
|
+
category = Category.new(item.css("th")[0].text)
|
79
|
+
category_list << category
|
65
80
|
end
|
66
81
|
category_list
|
67
82
|
end
|
68
83
|
end
|
69
84
|
|
70
|
-
def scrape_category_items(
|
85
|
+
def scrape_category_items(restaurant, category)
|
71
86
|
item_list = []
|
72
|
-
|
73
|
-
|
87
|
+
url = "#{restaurant.url}"
|
88
|
+
site = Nokogiri::HTML(open(url))
|
89
|
+
case restaurant.name
|
74
90
|
when "Burger King"
|
75
91
|
site = site.css("div table tbody tr")
|
76
92
|
site.each do |item|
|
77
93
|
if item.to_s.include?("<h3>")
|
78
|
-
if item.css("h3")[0].text ==
|
94
|
+
if item.css("h3")[0].text == restaurant.categories[category].name
|
79
95
|
next_item = item.next_element
|
80
96
|
begin
|
81
97
|
if next_item.to_s.include?("<td>") && !next_item.to_s.include?("<span") && !next_item.to_s.include?("header")
|
82
|
-
item_list << next_item.css("td")[0].text
|
98
|
+
item_list << Item.new(next_item.css("td")[0].text)
|
83
99
|
end
|
84
100
|
next_item = next_item.next_element
|
85
101
|
next_item == nil ? next_item = "<h3>" : next_item
|
@@ -92,11 +108,11 @@ class Scraper
|
|
92
108
|
site = site.css("div table tbody tr")
|
93
109
|
site.each do |item|
|
94
110
|
if item.to_s.include?("<h3>")
|
95
|
-
if item.css("h3")[0].text ==
|
111
|
+
if item.css("h3")[0].text == restaurant.categories[category].name
|
96
112
|
next_item = item.next_element
|
97
113
|
begin
|
98
114
|
if next_item.to_s.include?("<td>") && !next_item.to_s.include?("<span") && !next_item.to_s.include?("header")
|
99
|
-
item_list << next_item.css("td")[0].text
|
115
|
+
item_list << Item.new(next_item.css("td")[0].text)
|
100
116
|
end
|
101
117
|
next_item = next_item.next_element
|
102
118
|
next_item == nil ? next_item = "<h3>" : next_item
|
@@ -109,11 +125,11 @@ class Scraper
|
|
109
125
|
site = site.css("div table tbody tr")
|
110
126
|
site.each do |item|
|
111
127
|
if item.to_s.include?("<h3>")
|
112
|
-
if item.css("h3")[0].text ==
|
128
|
+
if item.css("h3")[0].text == restaurant.categories[category].name
|
113
129
|
next_item = item.next_element
|
114
130
|
begin
|
115
131
|
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 != " "
|
116
|
-
item_list << next_item.css("td")[0].text
|
132
|
+
item_list << Item.new(next_item.css("td")[0].text)
|
117
133
|
end
|
118
134
|
next_item = next_item.next_element
|
119
135
|
next_item == nil ? next_item = "<h3>" : next_item
|
@@ -126,10 +142,10 @@ class Scraper
|
|
126
142
|
site = site.css("div table tbody tr")
|
127
143
|
site.each do |item|
|
128
144
|
if item.to_s.include?("<strong>")
|
129
|
-
if item.css("strong")[0].text ==
|
145
|
+
if item.css("strong")[0].text == restaurant.categories[category].name
|
130
146
|
next_item = item.next_element
|
131
147
|
begin
|
132
|
-
item_list << next_item.css("td")[0].text if !next_item.to_s.include?("<span")
|
148
|
+
item_list << Item.new(next_item.css("td")[0].text) if !next_item.to_s.include?("<span")
|
133
149
|
next_item = next_item.next_element
|
134
150
|
next_item == nil ? next_item = "<strong>" : next_item
|
135
151
|
end while !next_item.to_s.include?("<strong>")
|
@@ -141,10 +157,10 @@ class Scraper
|
|
141
157
|
site = site.css("div table tbody tr")
|
142
158
|
site.each do |item|
|
143
159
|
if item.to_s.include?("rowheader")
|
144
|
-
if item.css("td")[0].text ==
|
160
|
+
if item.css("td")[0].text == restaurant.categories[category].name
|
145
161
|
next_item = item.next_element
|
146
162
|
begin
|
147
|
-
item_list << next_item.css("td")[0].text if !next_item.to_s.include?("<span")
|
163
|
+
item_list << Item.new(next_item.css("td")[0].text) if !next_item.to_s.include?("<span")
|
148
164
|
next_item = next_item.next_element
|
149
165
|
next_item == nil ? next_item = "<rowheader>" : next_item
|
150
166
|
end while !next_item.to_s.include?("rowheader")
|
@@ -156,10 +172,10 @@ class Scraper
|
|
156
172
|
site = site.css("div table tbody tr")
|
157
173
|
site.each do |item|
|
158
174
|
if item.to_s.include?("<th>")
|
159
|
-
if item.css("th")[0].text ==
|
175
|
+
if item.css("th")[0].text == restaurant.categories[category].name
|
160
176
|
next_item = item.next_element
|
161
177
|
begin
|
162
|
-
item_list << next_item.css("td")[0].text if !next_item.to_s.include?("<span")
|
178
|
+
item_list << Item.new(next_item.css("td")[0].text) if !next_item.to_s.include?("<span")
|
163
179
|
next_item = next_item.next_element
|
164
180
|
next_item == nil ? next_item = "<th>" : next_item
|
165
181
|
end while !next_item.to_s.include?("<th>")
|
@@ -170,18 +186,18 @@ class Scraper
|
|
170
186
|
end
|
171
187
|
end
|
172
188
|
|
173
|
-
def scrape_nutrition_info(
|
189
|
+
def scrape_nutrition_info(restaurant, cat_picked, item_picked)
|
174
190
|
index = 1
|
175
191
|
nutrition_list = []
|
176
|
-
site = Nokogiri::HTML(open(
|
177
|
-
case restaurant
|
192
|
+
site = Nokogiri::HTML(open(restaurant.url))
|
193
|
+
case restaurant.name
|
178
194
|
when "Burger King"
|
179
195
|
nutrition_items = site.css("div table thead tr th")
|
180
196
|
nutrition_items.each {|desc| nutrition_list << [desc.text.strip, ""]}
|
181
197
|
site = site.css("div table tbody tr")
|
182
198
|
site.each do |item|
|
183
199
|
if item.to_s.include?("<td>")
|
184
|
-
if item.css("td")[0].text ==
|
200
|
+
if item.css("td")[0].text == restaurant.categories[cat_picked].items[item_picked].name
|
185
201
|
i = 0
|
186
202
|
while i < nutrition_list.length
|
187
203
|
nutrition_list[i][1] = item.css("td")[i].text
|
@@ -198,7 +214,7 @@ class Scraper
|
|
198
214
|
site = site.css("div table tbody tr")
|
199
215
|
site.each do |item|
|
200
216
|
if item.to_s.include?("<td>")
|
201
|
-
if item.css("td")[0].text ==
|
217
|
+
if item.css("td")[0].text == restaurant.categories[cat_picked].items[item_picked].name
|
202
218
|
i = 0
|
203
219
|
while i < nutrition_list.length
|
204
220
|
nutrition_list[i][1] = item.css("td")[i].text
|
@@ -215,7 +231,7 @@ class Scraper
|
|
215
231
|
site = site.css("div table tbody tr")
|
216
232
|
site.each do |item|
|
217
233
|
if item.to_s.include?("<td>")
|
218
|
-
if item.css("td")[0].text ==
|
234
|
+
if item.css("td")[0].text == restaurant.categories[cat_picked].items[item_picked].name
|
219
235
|
i = 0
|
220
236
|
while i < nutrition_list.length
|
221
237
|
nutrition_list[i][1] = item.css("td")[i].text
|
data/lib/Fast_Food_Nutrition.rb
CHANGED
@@ -1,3 +1,6 @@
|
|
1
1
|
require_relative "./Fast_Food_Nutrition/version"
|
2
2
|
require_relative "./Fast_Food_Nutrition/cli"
|
3
3
|
require_relative "./Fast_Food_Nutrition/scraper"
|
4
|
+
require_relative "./Fast_Food_Nutrition/restaurant"
|
5
|
+
require_relative "./Fast_Food_Nutrition/category"
|
6
|
+
require_relative "./Fast_Food_Nutrition/items"
|
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: 0.
|
4
|
+
version: 0.2.0
|
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-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: open_uri_redirections
|
@@ -108,7 +108,10 @@ files:
|
|
108
108
|
- bin/ff_nutrition
|
109
109
|
- bin/setup
|
110
110
|
- lib/Fast_Food_Nutrition.rb
|
111
|
+
- lib/Fast_Food_Nutrition/category.rb
|
111
112
|
- lib/Fast_Food_Nutrition/cli.rb
|
113
|
+
- lib/Fast_Food_Nutrition/items.rb
|
114
|
+
- lib/Fast_Food_Nutrition/restaurant.rb
|
112
115
|
- lib/Fast_Food_Nutrition/scraper.rb
|
113
116
|
- lib/Fast_Food_Nutrition/version.rb
|
114
117
|
- spec.md
|