Fast_Food_Nutrition 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: d6d91d9e922a4445184cbe3f025eff17e794d745875c071624e27d31bb437a33
4
+ data.tar.gz: b0c8ffd6947c2f4206cd86f829c5c9b7fc9f30008d8b008e5885d6ec96b56e4b
5
+ SHA512:
6
+ metadata.gz: e1fb70c3dcfcf2fffcde6c73daf0edbe23e425435d765f0803c03224d832121a15d83bd1a2227097c5166e9403dc9f211351329626a8b5757eaff3c66ec670fc
7
+ data.tar.gz: df126e92d5d929f68b4d6c7d73fd6d265f417da81e746e9ce78e6c07873df50ef314ec187c74281a5cd3e9ada3264793c4ae762b3c1af00b3971153c4e86e7ce
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.3
5
+ before_install: gem install bundler -v 1.16.2
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at elreymcd@yahoo.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
Binary file
@@ -0,0 +1,41 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "Fast_Food_Nutrition/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "Fast_Food_Nutrition"
8
+ spec.version = FastFoodNutrition::VERSION
9
+ spec.authors = ["Daniel Hernandez"]
10
+ spec.email = ["elreymcd@yahoo.com"]
11
+
12
+ spec.summary = "Finds nutrition information for items from top QSRs"
13
+ spec.description = "Finds nutrition information for items from top QSRs"
14
+ spec.homepage = "http://rubygems.org/gems/Fast_Food_Nutrition"
15
+ spec.license = "MIT"
16
+
17
+ spec.add_dependency 'open_uri_redirections', '~> 0.2.1'
18
+ spec.add_dependency 'nokogiri', '~> 1.8', '>= 1.8.2'
19
+
20
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
21
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
22
+ # if spec.respond_to?(:metadata)
23
+ # spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
24
+ # else
25
+ # raise "RubyGems 2.0 or newer is required to protect against " \
26
+ # "public gem pushes."
27
+ # end
28
+
29
+ # Specify which files should be added to the gem when it is released.
30
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
31
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
32
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
33
+ end
34
+ spec.bindir = "exe"
35
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
36
+ spec.require_paths = ["lib"]
37
+
38
+ spec.add_development_dependency "bundler", "~> 1.16"
39
+ spec.add_development_dependency "rake", "~> 10.0"
40
+ spec.add_development_dependency "rspec", "~> 3.0"
41
+ end
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in Fast_Food_Nutrition.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,41 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ Fast_Food_Nutrition (0.1.0)
5
+ nokogiri (~> 1.8, >= 1.8.2)
6
+ open_uri_redirections (~> 0.2.1)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ diff-lcs (1.3)
12
+ mini_portile2 (2.3.0)
13
+ nokogiri (1.8.2)
14
+ mini_portile2 (~> 2.3.0)
15
+ open_uri_redirections (0.2.1)
16
+ rake (10.5.0)
17
+ rspec (3.7.0)
18
+ rspec-core (~> 3.7.0)
19
+ rspec-expectations (~> 3.7.0)
20
+ rspec-mocks (~> 3.7.0)
21
+ rspec-core (3.7.1)
22
+ rspec-support (~> 3.7.0)
23
+ rspec-expectations (3.7.0)
24
+ diff-lcs (>= 1.2.0, < 2.0)
25
+ rspec-support (~> 3.7.0)
26
+ rspec-mocks (3.7.0)
27
+ diff-lcs (>= 1.2.0, < 2.0)
28
+ rspec-support (~> 3.7.0)
29
+ rspec-support (3.7.1)
30
+
31
+ PLATFORMS
32
+ ruby
33
+
34
+ DEPENDENCIES
35
+ Fast_Food_Nutrition!
36
+ bundler (~> 1.16)
37
+ rake (~> 10.0)
38
+ rspec (~> 3.0)
39
+
40
+ BUNDLED WITH
41
+ 1.16.2
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Daniel Hernandez
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,42 @@
1
+ # FastFoodNutrition
2
+
3
+ The Fast Food Nutrition gem is a command line interface tool that will get nutrition information for menu items from several of the top Fast Food and Quick service restaurants in the country.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'Fast_Food_Nutrition'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install Fast_Food_Nutrition
20
+
21
+ ## Usage
22
+
23
+ Once installed, cd into Fast_Food_Nutrition folder and execute ruby bin/ff_nutrition from the main folder on your terminal.
24
+ User will select a restaurant from the list supplied, then choose a category, then choose and item. The nutrition information for the item will be returned. User will have to option to search for another item or end the program.
25
+
26
+ ## Development
27
+
28
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
29
+
30
+ 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).
31
+
32
+ ## Contributing
33
+
34
+ Bug reports and pull requests are welcome on GitHub at https://github.com/<github minasman>/Fast_Food_Nutrition. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
35
+
36
+ ## License
37
+
38
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
39
+
40
+ ## Code of Conduct
41
+
42
+ Everyone interacting in the FastFoodNutrition project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/<github username>/Fast_Food_Nutrition/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "Fast_Food_Nutrition"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/ff_nutrition ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "./lib/Fast_Food_Nutrition"
4
+ Welcome.new.intro
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,59 @@
1
+ class Welcome
2
+
3
+ def intro
4
+ puts "Welcome To The Fast Food Nutrition Finder"
5
+ list_restaurants
6
+ end
7
+
8
+ def list_restaurants
9
+ selection = 0
10
+ puts "\nPlease select a Restaurant by number:"
11
+ restaurants = Scraper.new.scrape_site_for_restaurants("http://www.nutrition-charts.com/")
12
+ restaurants.each_with_index {|restaurant, i| puts "#{i + 1}: #{restaurant.flatten[0]}"}
13
+ selection = gets.strip.to_i until selection > 0 && selection <= restaurants.length
14
+ puts "\nYou selected #{restaurants[selection - 1].flatten[0]}"
15
+ select_category(Scraper.new.scrape_restaurant_categories(restaurants[selection - 1]),"http://www.nutrition-charts.com/#{restaurants[selection - 1].flatten[1]}", restaurants[selection - 1].flatten[0])
16
+ end
17
+
18
+ def select_category(categories, item_site, restaurant)
19
+ selection = 0
20
+ 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.length
23
+ puts "\nYou selected #{categories[selection - 1]}"
24
+ select_item(Scraper.new.scrape_category_items(categories[selection - 1], selection, item_site, restaurant), item_site, restaurant)
25
+ end
26
+
27
+ def select_item(menu_item_list,item_site, restaurant)
28
+ i = 1
29
+ selection = 0
30
+ puts "\nPlease select an item:"
31
+ menu_item_list.each do |item|
32
+ puts "#{i}: #{item}"
33
+ i += 1
34
+ end
35
+ selection = gets.strip.to_i until selection > 0 && selection <= menu_item_list.length
36
+ puts "\nYou selected #{menu_item_list[selection - 1]}"
37
+ get_nutrition(Scraper.new.scrape_nutrition_info(menu_item_list[selection - 1], item_site, restaurant), menu_item_list[selection - 1])
38
+ end
39
+
40
+ def get_nutrition(nutrition_list, item_name)
41
+ puts "\nHere is the nutrition information for #{item_name}:"
42
+ nutrition_list.each do |item|
43
+ puts " #{item[0]}: #{item[1]}"
44
+ end
45
+ continue?
46
+ end
47
+
48
+ def continue?
49
+ input = ""
50
+ puts "\nWould you like to continue to find more items? (y/n)"
51
+ input = gets.strip.downcase until input == "y" || input == "n"
52
+ input == "y" ? list_restaurants : bye
53
+ end
54
+
55
+ def bye
56
+ puts "\nThank You for using the Fast Food Nutrition Finder"
57
+ end
58
+
59
+ end
@@ -0,0 +1,231 @@
1
+ require 'nokogiri'
2
+ require 'open-uri'
3
+ require 'pry'
4
+
5
+ class Scraper
6
+ def scrape_site_for_restaurants(url)
7
+ restaurants = []
8
+ site = Nokogiri::HTML(open(url))
9
+ site = site.css("div.entry-content table tbody tr")
10
+ site.each do |restaurant|
11
+ restaurants << {restaurant.css("td")[1].css("a").text.strip => restaurant.css("td")[1].css("a").attribute("href").value}
12
+ restaurants << {restaurant.css("td")[3].css("a").text.strip => restaurant.css("td")[3].css("a").attribute("href").value}
13
+ end
14
+ restaurants
15
+ end
16
+
17
+ def scrape_restaurant_categories(category)
18
+ category_list = []
19
+ url = "http://www.nutrition-charts.com/#{category.flatten[1]}"
20
+ site = Nokogiri::HTML(open(url))
21
+ case category.flatten[0]
22
+ when "Burger King"
23
+ site = site.css("div table tbody td h3")
24
+ site.each do |item|
25
+ category_list << item.text
26
+ end
27
+ category_list
28
+ when "Wendys"
29
+ site = site.css("div table tbody td h3")
30
+ site.each do |item|
31
+ category_list << item.text
32
+ end
33
+ category_list
34
+ when "Buffalo Wild Wings"
35
+ site = site.css("div table tbody td h3")
36
+ site.each do |item|
37
+ category_list << item.text
38
+ end
39
+ category_list
40
+ when "Pizza Hut"
41
+ site = site.css("div table tbody td strong")
42
+ site.each do |item|
43
+ category_list << item.text
44
+ end
45
+ category_list
46
+ when "Applebees"
47
+ site = site.css("div table tbody")
48
+ site = site.css("tr.rowheader")
49
+ site.each do |item|
50
+ category_list << item.css("td")[0].text
51
+ end
52
+ category_list
53
+ when "Baja Fresh"
54
+ site = site.css("div table tbody tr")
55
+ site.each do |item|
56
+ item.to_s.include?("<th>") ? category_list << item.css("th")[0].text : ""
57
+ end
58
+ category_list
59
+ else
60
+ site = site.css("div table tbody")
61
+ category_list << site[0].css("tr")[0].css("th")[0].text
62
+ site = site.css("tr.rowheader")
63
+ site.each do |item|
64
+ category_list << item.css("th")[0].text
65
+ end
66
+ category_list
67
+ end
68
+ end
69
+
70
+ def scrape_category_items(item_name, index, item_site, restaurant)
71
+ item_list = []
72
+ site = Nokogiri::HTML(open(item_site))
73
+ case restaurant
74
+ when "Burger King"
75
+ site = site.css("div table tbody tr")
76
+ site.each do |item|
77
+ if item.to_s.include?("<h3>")
78
+ if item.css("h3")[0].text == item_name
79
+ next_item = item.next_element
80
+ begin
81
+ 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
83
+ end
84
+ next_item = next_item.next_element
85
+ next_item == nil ? next_item = "<h3>" : next_item
86
+ end while !next_item.to_s.include?("<h3>")
87
+ end
88
+ end
89
+ end
90
+ item_list
91
+ when "Wendys"
92
+ site = site.css("div table tbody tr")
93
+ site.each do |item|
94
+ if item.to_s.include?("<h3>")
95
+ if item.css("h3")[0].text == item_name
96
+ next_item = item.next_element
97
+ begin
98
+ 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
100
+ end
101
+ next_item = next_item.next_element
102
+ next_item == nil ? next_item = "<h3>" : next_item
103
+ end while !next_item.to_s.include?("<h3>")
104
+ end
105
+ end
106
+ end
107
+ item_list
108
+ when "Buffalo Wild Wings"
109
+ site = site.css("div table tbody tr")
110
+ site.each do |item|
111
+ if item.to_s.include?("<h3>")
112
+ if item.css("h3")[0].text == item_name
113
+ next_item = item.next_element
114
+ begin
115
+ 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
117
+ end
118
+ next_item = next_item.next_element
119
+ next_item == nil ? next_item = "<h3>" : next_item
120
+ end while !next_item.to_s.include?("<h3>")
121
+ end
122
+ end
123
+ end
124
+ item_list
125
+ when "Pizza Hut"
126
+ site = site.css("div table tbody tr")
127
+ site.each do |item|
128
+ if item.to_s.include?("<strong>")
129
+ if item.css("strong")[0].text == item_name
130
+ next_item = item.next_element
131
+ begin
132
+ item_list << next_item.css("td")[0].text if !next_item.to_s.include?("<span")
133
+ next_item = next_item.next_element
134
+ next_item == nil ? next_item = "<strong>" : next_item
135
+ end while !next_item.to_s.include?("<strong>")
136
+ end
137
+ end
138
+ end
139
+ item_list
140
+ when "Applebees"
141
+ site = site.css("div table tbody tr")
142
+ site.each do |item|
143
+ if item.to_s.include?("rowheader")
144
+ if item.css("td")[0].text == item_name
145
+ next_item = item.next_element
146
+ begin
147
+ item_list << next_item.css("td")[0].text if !next_item.to_s.include?("<span")
148
+ next_item = next_item.next_element
149
+ next_item == nil ? next_item = "<rowheader>" : next_item
150
+ end while !next_item.to_s.include?("rowheader")
151
+ end
152
+ end
153
+ end
154
+ item_list
155
+ else
156
+ site = site.css("div table tbody tr")
157
+ site.each do |item|
158
+ if item.to_s.include?("<th>")
159
+ if item.css("th")[0].text == item_name
160
+ next_item = item.next_element
161
+ begin
162
+ item_list << next_item.css("td")[0].text if !next_item.to_s.include?("<span")
163
+ next_item = next_item.next_element
164
+ next_item == nil ? next_item = "<th>" : next_item
165
+ end while !next_item.to_s.include?("<th>")
166
+ end
167
+ end
168
+ end
169
+ item_list
170
+ end
171
+ end
172
+
173
+ def scrape_nutrition_info(item_name, item_site, restaurant)
174
+ index = 1
175
+ nutrition_list = []
176
+ site = Nokogiri::HTML(open(item_site))
177
+ case restaurant
178
+ when "Burger King"
179
+ nutrition_items = site.css("div table thead tr th")
180
+ nutrition_items.each {|desc| nutrition_list << [desc.text.strip, ""]}
181
+ site = site.css("div table tbody tr")
182
+ site.each do |item|
183
+ if item.to_s.include?("<td>")
184
+ if item.css("td")[0].text == item_name
185
+ i = 0
186
+ while i < nutrition_list.length
187
+ nutrition_list[i][1] = item.css("td")[i].text
188
+ i += 1
189
+ end
190
+ end
191
+ end
192
+ end #do
193
+ nutrition_list.shift
194
+ nutrition_list
195
+ when "Pizza Hut"
196
+ nutrition_items = site.css("div table tbody tr th")
197
+ nutrition_items.each {|desc| nutrition_list << [desc.text.strip, ""]}
198
+ site = site.css("div table tbody tr")
199
+ site.each do |item|
200
+ if item.to_s.include?("<td>")
201
+ if item.css("td")[0].text == item_name
202
+ i = 0
203
+ while i < nutrition_list.length
204
+ nutrition_list[i][1] = item.css("td")[i].text
205
+ i += 1
206
+ end
207
+ end
208
+ end
209
+ end #do
210
+ nutrition_list.shift
211
+ nutrition_list
212
+ else
213
+ nutrition_items = site.css("div table thead tr th")
214
+ nutrition_items.each {|desc| nutrition_list << [desc.text.strip, ""]}
215
+ site = site.css("div table tbody tr")
216
+ site.each do |item|
217
+ if item.to_s.include?("<td>")
218
+ if item.css("td")[0].text == item_name
219
+ i = 0
220
+ while i < nutrition_list.length
221
+ nutrition_list[i][1] = item.css("td")[i].text
222
+ i += 1
223
+ end
224
+ end
225
+ end
226
+ end #do
227
+ nutrition_list.shift
228
+ nutrition_list
229
+ end
230
+ end
231
+ end
@@ -0,0 +1,3 @@
1
+ module FastFoodNutrition
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,3 @@
1
+ require_relative "./Fast_Food_Nutrition/version"
2
+ require_relative "./Fast_Food_Nutrition/cli"
3
+ require_relative "./Fast_Food_Nutrition/scraper"
data/spec.md ADDED
@@ -0,0 +1,8 @@
1
+ # Specifications for the CLI Assessment
2
+
3
+ Specs:
4
+ - [x] Have a CLI for interfacing with the application
5
+ - [x] Pull data from an external source
6
+ The gem uses Open-uri and Nokogiri to open http://nutrition-charts.com and scrape restaurants, restaurant categories, category items and finally the nutrition information for those items. On the site, the restaurant names are scraped from the homepage along with a link to the url containing the information for the restaurant. Once the user selects a restaurant, the link is scraped to category, item and nutrition information.
7
+ - [x] Implement both list and detail views
8
+ The user is first presented with a list view of restaurants. Based on the users choice, the user is then presented with a list of categories from the restaurant chosen. Next the user is presented with a list of items from withen the category chosen. Finally, a detailed view of the nutrition information for the item is presented to the user.
metadata ADDED
@@ -0,0 +1,139 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: Fast_Food_Nutrition
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Daniel Hernandez
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-06-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: open_uri_redirections
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.2.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.2.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: nokogiri
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.8'
34
+ - - ">="
35
+ - !ruby/object:Gem::Version
36
+ version: 1.8.2
37
+ type: :runtime
38
+ prerelease: false
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - "~>"
42
+ - !ruby/object:Gem::Version
43
+ version: '1.8'
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: 1.8.2
47
+ - !ruby/object:Gem::Dependency
48
+ name: bundler
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '1.16'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '1.16'
61
+ - !ruby/object:Gem::Dependency
62
+ name: rake
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '10.0'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '10.0'
75
+ - !ruby/object:Gem::Dependency
76
+ name: rspec
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: '3.0'
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: '3.0'
89
+ description: Finds nutrition information for items from top QSRs
90
+ email:
91
+ - elreymcd@yahoo.com
92
+ executables: []
93
+ extensions: []
94
+ extra_rdoc_files: []
95
+ files:
96
+ - ".gitignore"
97
+ - ".rspec"
98
+ - ".travis.yml"
99
+ - CODE_OF_CONDUCT.md
100
+ - Demo_Walkthrough.mov
101
+ - Fast_Food_Nutrition.gemspec
102
+ - Gemfile
103
+ - Gemfile.lock
104
+ - LICENSE.txt
105
+ - README.md
106
+ - Rakefile
107
+ - bin/console
108
+ - bin/ff_nutrition
109
+ - bin/setup
110
+ - lib/Fast_Food_Nutrition.rb
111
+ - lib/Fast_Food_Nutrition/cli.rb
112
+ - lib/Fast_Food_Nutrition/scraper.rb
113
+ - lib/Fast_Food_Nutrition/version.rb
114
+ - spec.md
115
+ homepage: http://rubygems.org/gems/Fast_Food_Nutrition
116
+ licenses:
117
+ - MIT
118
+ metadata: {}
119
+ post_install_message:
120
+ rdoc_options: []
121
+ require_paths:
122
+ - lib
123
+ required_ruby_version: !ruby/object:Gem::Requirement
124
+ requirements:
125
+ - - ">="
126
+ - !ruby/object:Gem::Version
127
+ version: '0'
128
+ required_rubygems_version: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ requirements: []
134
+ rubyforge_project:
135
+ rubygems_version: 2.7.7
136
+ signing_key:
137
+ specification_version: 4
138
+ summary: Finds nutrition information for items from top QSRs
139
+ test_files: []