eatable 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
+ SHA1:
3
+ metadata.gz: 75cd3c25dfd793b07012fe3e69440c08cb9ae0c7
4
+ data.tar.gz: 9ddcbbb49440cc39ff7ce4de3f257ae438862d50
5
+ SHA512:
6
+ metadata.gz: 1b851c10352da67f72fc3d63045be0a5a63e0012e35ce2548c227a594c2febc7d26144baf2a4245d1b9067433b347c47c252c5810db9f8b7c79a9ae175e38cb2
7
+ data.tar.gz: 831d00ce3215aa2b8db10fb1c2c2d4aa46c821c119cd2668403891293e9c0ae0e0f4bf3f57a9daa18a364c1e618f9dab8e1f594019f3300a70810f21b1a07104
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/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.3
4
+ before_install: gem install bundler -v 1.11.2
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at lkwlala@gmail.com. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'nokogiri'
4
+
5
+ gem 'pry'
6
+
7
+
8
+
9
+ # Specify your gem's dependencies in eatable.gemspec
10
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Lindsey Wells
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/NOTES.md ADDED
@@ -0,0 +1,25 @@
1
+ http://www.menupages.com (new york city_name = "www")
2
+
3
+ http://sanfrancisco.menupages.com/
4
+
5
+ http://losangeles.menupages.com/
6
+
7
+ http://washingtondc.menupages.com/
8
+
9
+ http://southflorida.menupages.com/
10
+
11
+ citypg.css('#image-map area').first.attr('href')
12
+ neighb_pg.css('tbody').first
13
+ neighb_pg.css('tbody tr td a').first.attr('href')
14
+ => "/restaurants/zigo/"
15
+
16
+ Should I refactor to find correct css selector, so I don't need to filter for grubhub and seamless?
17
+
18
+ In case I want to add zip code: menupg.css('span.city-zip').text
19
+
20
+ /\u00A0/ Regex for nbsp characters (to get rid of the weird spaces!!)
21
+
22
+
23
+
24
+
25
+
data/README.md ADDED
@@ -0,0 +1,41 @@
1
+ # Eatable
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/eatable`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'eatable'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install eatable
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ 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.
30
+
31
+ 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).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/eatable. 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.
36
+
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
41
+
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,19 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "eatable"
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
+
11
+ require "pry"
12
+ Pry.start
13
+
14
+ require "irb"
15
+ IRB.start
16
+
17
+
18
+
19
+
data/bin/eatable ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "eatable"
5
+
6
+ Eatable::CLI.new.call
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
data/eatable.gemspec ADDED
@@ -0,0 +1,34 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'eatable/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "eatable"
8
+ spec.version = Eatable::VERSION
9
+ spec.authors = ["Lindsey Wells"]
10
+ spec.email = ["lkwlala@gmail.com"]
11
+
12
+ spec.summary = %q{CLI restaurant scanner which detects occurrences of allergens listed on menus.}
13
+ spec.homepage = "https://github.com/LKWLaLa/eatable"
14
+ spec.license = "MIT"
15
+
16
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
17
+ # delete this section to allow pushing this gem to any host.
18
+ #if spec.respond_to?(:metadata)
19
+ # spec.metadata['allowed_push_host'] = "http://mygemserver.com"
20
+ # else
21
+ # raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
22
+ # end
23
+
24
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
25
+ #spec.bindir = "exe"
26
+ spec.bindir = "bin"
27
+ #spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.executables = ["eatable"]
29
+ spec.require_paths = ["lib"]
30
+
31
+ spec.add_development_dependency "bundler", "~> 1.11"
32
+ spec.add_development_dependency "rake", "~> 10.0"
33
+ spec.add_development_dependency "rspec", "~> 3.0"
34
+ end
data/lib/eatable.rb ADDED
@@ -0,0 +1,5 @@
1
+
2
+ require 'eatable/version'
3
+ require 'eatable/cli'
4
+ require 'eatable/scraper'
5
+ require 'eatable/restaurant'
@@ -0,0 +1,103 @@
1
+ require 'pry'
2
+
3
+ class Eatable::CLI
4
+
5
+ AREAS = ["New York", "San Francisco", "Los Angeles", "Philadelphia", "Boston",
6
+ "Chicago", "Washington, DC", "South Florida"]
7
+
8
+ attr_accessor :a_input, :n_input, :neighborhoods, :city_name
9
+
10
+
11
+ def call
12
+ self.greeting
13
+ self.select_area
14
+ self.select_neighborhood
15
+ self.list_restaurants
16
+ end
17
+
18
+ def quit
19
+ puts "-" * 24
20
+ puts "\nSee you later! \u{2615}"
21
+ exit(0)
22
+ end
23
+
24
+
25
+ def greeting
26
+ puts "_" * 85, "\n"
27
+ puts "Hi there, welcome to Eatable! \u{1f370} \u{1f374}"
28
+ puts "Restaurants can currently be screened in the following areas:"
29
+ puts "_" * 85, "\n"
30
+ AREAS.sort.each_with_index {|a, i| puts "#{i + 1}. #{a}" }
31
+ end
32
+
33
+
34
+ def select_area
35
+ puts "\nWhich area would you like to search? (Please type the number, or 0 to quit.)"
36
+ print "=> "
37
+ self.a_input = gets.strip.to_i
38
+ if self.a_input == 0
39
+ self.quit
40
+ else
41
+ puts "\nOk! Let's check #{AREAS.sort[self.a_input - 1]}..."
42
+ puts "_" * 85, "\n"
43
+ end
44
+ end
45
+
46
+
47
+ def select_neighborhood
48
+ puts "Available neighborhoods:"
49
+ puts "-" * 24
50
+ @city_name = (AREAS.sort[self.a_input - 1]).downcase.gsub(/\s|,/, "")
51
+ if @city_name == "newyork"
52
+ @city_name = "www"
53
+ end
54
+ @neighborhoods = Eatable::Scraper.neighborhood_scrape(@city_name)
55
+ self.neighborhoods.each_with_index {|(k,v), i| puts "#{i + 1}. #{k}"}
56
+ puts "\nWhere are you thinking of eating? (select the neighborhood number, or 0 to quit)"
57
+ print "=> "
58
+ self.n_input = gets.strip.to_i
59
+ if self.n_input == 0
60
+ self.quit
61
+ else
62
+ k = self.neighborhoods.keys
63
+ puts "\nOk! Screening #{k[self.n_input - 1]} restaurant menus... This may take a few minutes..."
64
+ puts "_" * 90, "\n"
65
+ end
66
+ end
67
+
68
+
69
+ def list_restaurants
70
+ valid_restaurants = Eatable::Scraper.restaurant_scrape(self.neighborhood_url)
71
+ puts "Here are some potential options!"
72
+ puts "-" * 31
73
+ valid_restaurants.each do |restaurant|
74
+ puts "\n #{restaurant["name"]}\n #{restaurant["address"]}\n #{restaurant["phone"]}"
75
+ end
76
+ puts "_" * 85
77
+ puts "\nWould you like to search another area? (Y/n)?"
78
+ print "=> "
79
+ input = gets.strip.downcase
80
+ if input == 'y'
81
+ self.call
82
+ else
83
+ quit
84
+ end
85
+ end
86
+
87
+
88
+ def neighborhood_url
89
+ k = self.neighborhoods.keys
90
+ self.neighborhoods[k[self.n_input - 1]]
91
+ end
92
+
93
+
94
+
95
+ end
96
+
97
+
98
+
99
+
100
+
101
+
102
+
103
+
@@ -0,0 +1,22 @@
1
+ class Eatable::Restaurant
2
+
3
+ @@all = []
4
+
5
+ attr_accessor :name, :address, :phone, :website, :menu
6
+
7
+ def initialize(hash)
8
+ hash.each {|k, v| self.send('#{k}=', v)}
9
+ @@all << self
10
+ end
11
+
12
+ def self.all
13
+ @@all
14
+ end
15
+
16
+ def self.reset
17
+ self.class.all.clear
18
+ end
19
+
20
+
21
+
22
+ end
@@ -0,0 +1,79 @@
1
+ require 'open-uri'
2
+ require 'nokogiri'
3
+ require 'pry'
4
+
5
+ class Eatable::Scraper
6
+
7
+ NUTS = /nut|almond|cashew|macadamia|pecan|pigñolia|pistachio|praline|pesto|filbert/
8
+ SHELL_FISH = /shrimp|clam|mussel|lobster|crab|prawn/
9
+
10
+
11
+ def self.neighborhood_scrape(city_name)
12
+ neighborhoods = {}
13
+ @@city_url = 'http://' + city_name + '.menupages.com'
14
+ citypg = Nokogiri::HTML(open(@@city_url))
15
+
16
+ citypg.css('#image-map area').each do |a|
17
+ neighborhood_url = a.attr('href')
18
+ name = a.attr('alt')
19
+ neighborhoods[name] = neighborhood_url
20
+ end
21
+ neighborhoods
22
+ end
23
+
24
+
25
+ def self.restaurant_scrape(neighborhood_url)
26
+ menus_array = []
27
+
28
+ self.full_neighborhood_url=(neighborhood_url)
29
+ neighb_pg = Nokogiri::HTML(open(self.full_neighborhood_url))
30
+ rest_table = neighb_pg.css('tbody tr td a')
31
+ rest_table.each do|listing|
32
+ menus_array << listing.attr('href') unless ((listing.attr('href')).include?('grubhub') || (listing.attr('href')).include?('seamless'))
33
+ end
34
+ menus_array.map! {|link| self.city_url + link + "menu"}
35
+
36
+ self.filter_menus(menus_array)
37
+ end
38
+
39
+
40
+
41
+ def self.filter_menus(menus_array)
42
+ valid_restaurants = []
43
+
44
+ menus_array[0..10].each do |menu|
45
+ menupg = Nokogiri::HTML(open(menu))
46
+ menu_body = (menupg.css('div #restaurant-menu').text.gsub(/\r\n/, "").gsub(/\u00A0/, "")).downcase
47
+ # --------------- Adjust tolerence level for number of search terms -----------------------------
48
+ if (menu_body.scan(NUTS).length <= 2) && (menu_body.scan(SHELL_FISH).length <= 2) && (menu_body.length > 20)
49
+ restaurant = {
50
+ "name" => menupg.css('div h1.title1respage').text,
51
+ "address" => "#{menupg.css('span.addr').text}",
52
+ "phone" => menupg.css('li.phonenew').text.gsub(/[\\rn\s]/, "")
53
+ }
54
+
55
+ valid_restaurants << restaurant
56
+ end
57
+ end
58
+ valid_restaurants
59
+ end
60
+
61
+
62
+ def self.city_url
63
+ @@city_url
64
+ end
65
+
66
+ def self.full_neighborhood_url=(neighborhood_url)
67
+ if @@city_url == "http://www.menupages.com"
68
+ @@full_neighborhood_url = neighborhood_url
69
+ else
70
+ @@full_neighborhood_url = @@city_url + neighborhood_url
71
+ end
72
+ end
73
+
74
+ def self.full_neighborhood_url
75
+ @@full_neighborhood_url
76
+ end
77
+
78
+
79
+ end
@@ -0,0 +1,3 @@
1
+ module Eatable
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,105 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: eatable
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Lindsey Wells
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-02-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.11'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.11'
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: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ description:
56
+ email:
57
+ - lkwlala@gmail.com
58
+ executables:
59
+ - eatable
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".gitignore"
64
+ - ".rspec"
65
+ - ".travis.yml"
66
+ - CODE_OF_CONDUCT.md
67
+ - Gemfile
68
+ - LICENSE.txt
69
+ - NOTES.md
70
+ - README.md
71
+ - Rakefile
72
+ - bin/console
73
+ - bin/eatable
74
+ - bin/setup
75
+ - eatable.gemspec
76
+ - lib/eatable.rb
77
+ - lib/eatable/cli.rb
78
+ - lib/eatable/restaurant.rb
79
+ - lib/eatable/scraper.rb
80
+ - lib/eatable/version.rb
81
+ homepage: https://github.com/LKWLaLa/eatable
82
+ licenses:
83
+ - MIT
84
+ metadata: {}
85
+ post_install_message:
86
+ rdoc_options: []
87
+ require_paths:
88
+ - lib
89
+ required_ruby_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ required_rubygems_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ requirements: []
100
+ rubyforge_project:
101
+ rubygems_version: 2.5.2
102
+ signing_key:
103
+ specification_version: 4
104
+ summary: CLI restaurant scanner which detects occurrences of allergens listed on menus.
105
+ test_files: []