brewery_search 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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8dd6e5adb32494110641bf24cb1c7593fc473adf
4
+ data.tar.gz: 47e0692432f79def8dc30b842d444ac1bc9a67cb
5
+ SHA512:
6
+ metadata.gz: 7494dec5ff0718015dcbd85e26151ce10b330c7eadf8c4e87b7654db1b4d5649452358def5e92e907a27c7605da3c28981521f365b5189d8fb9bc889a53e9372
7
+ data.tar.gz: c2be5751795e5f4065d0255919a5d79e1b2a9649a02b456aeca7217bf28a1c0be1d0b0a40a34338235d6dd46e0581dfc878d466e24d418671efaa11a3a8a3d75
data/.rspec_status ADDED
@@ -0,0 +1,4 @@
1
+ example_id | status | run_time |
2
+ ---------------------------------- | ------- | -------- |
3
+ ./spec/brewery_search_spec.rb[1:1] | unknown | |
4
+ ./spec/brewery_search_spec.rb[1:2] | unknown | |
@@ -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 btmcco8@gmail.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/
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ source "http://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ gem 'nokogiri', '~> 1.8', '>= 1.8.4'
6
+ gem 'launchy', '~> 2.4', '>= 2.4.3'
7
+ gem 'pry', '~> 0.11.3'
8
+ gem 'require_all', '~> 2.0'
9
+ gem 'rspec'
10
+
11
+ # Specify your gem's dependencies in brewery_search.gemspec
12
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,53 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ brewery_search (0.1.0)
5
+
6
+ GEM
7
+ remote: http://rubygems.org/
8
+ specs:
9
+ addressable (2.5.2)
10
+ public_suffix (>= 2.0.2, < 4.0)
11
+ coderay (1.1.2)
12
+ diff-lcs (1.3)
13
+ launchy (2.4.3)
14
+ addressable (~> 2.3)
15
+ method_source (0.9.0)
16
+ mini_portile2 (2.3.0)
17
+ nokogiri (1.8.4)
18
+ mini_portile2 (~> 2.3.0)
19
+ pry (0.11.3)
20
+ coderay (~> 1.1.0)
21
+ method_source (~> 0.9.0)
22
+ public_suffix (3.0.3)
23
+ rake (10.4.2)
24
+ require_all (2.0.0)
25
+ rspec (3.7.0)
26
+ rspec-core (~> 3.7.0)
27
+ rspec-expectations (~> 3.7.0)
28
+ rspec-mocks (~> 3.7.0)
29
+ rspec-core (3.7.1)
30
+ rspec-support (~> 3.7.0)
31
+ rspec-expectations (3.7.0)
32
+ diff-lcs (>= 1.2.0, < 2.0)
33
+ rspec-support (~> 3.7.0)
34
+ rspec-mocks (3.7.0)
35
+ diff-lcs (>= 1.2.0, < 2.0)
36
+ rspec-support (~> 3.7.0)
37
+ rspec-support (3.7.1)
38
+
39
+ PLATFORMS
40
+ ruby
41
+
42
+ DEPENDENCIES
43
+ brewery_search!
44
+ bundler (~> 1.16)
45
+ launchy (~> 2.4, >= 2.4.3)
46
+ nokogiri (~> 1.8, >= 1.8.4)
47
+ pry (~> 0.11.3)
48
+ rake (~> 10.0)
49
+ require_all (~> 2.0)
50
+ rspec
51
+
52
+ BUNDLED WITH
53
+ 1.16.4
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 btmccollum
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,51 @@
1
+ # BrewerySearch
2
+
3
+ BrewerySearch provides a CLI that allows a user to navigate BrewBound's brewery database and retrieve additional information such as contact information, social media links, general overview, and more.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'brewery_search'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install brewery_search
20
+
21
+ ## Usage
22
+
23
+ Type the following to get started:
24
+
25
+ $ brewery-search
26
+
27
+ Follow the on-screen prompts to continue.
28
+
29
+ Users will have the ability to search by state abbreviations (case senstitive). From there a user will be presented with a list of all registered breweries in that state. A user can call
30
+
31
+ $ city
32
+
33
+ to receive a prompt to filter by a specific city, otherwise they can select the number of any brewery for more information.
34
+
35
+ ## Development
36
+
37
+ 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.
38
+
39
+ 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).
40
+
41
+ ## Contributing
42
+
43
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/brewery_search. 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.
44
+
45
+ ## License
46
+
47
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
48
+
49
+ ## Code of Conduct
50
+
51
+ Everyone interacting in the BrewerySearch project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/brewery_search/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
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # require "bundler/setup"
4
+ # require "./config/environment.rb"
5
+ require_relative "../lib/brewery_search"
6
+
7
+ BrewerySearch::CLI.new.welcome_screen
data/bin/console ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "./config/environment.rb"
5
+ require "brewery_search"
6
+
7
+ require "irb"
8
+ IRB.start(__FILE__)
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,43 @@
1
+ lib = File.expand_path("../lib", __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "brewery_search/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "brewery_search"
7
+ spec.version = BrewerySearch::VERSION
8
+ spec.authors = ["btmccollum"]
9
+ spec.email = ["btmcco8@gmail.com"]
10
+
11
+ spec.summary = "A CLI brewery directory leveraging BrewBound"
12
+ spec.description = "Allows a user to search for breweries by state by utilizing the www.brewbound.com brewery database. A user can filter by city and obtain additional info about any entry."
13
+ spec.homepage = "https://github.com/btmccollum/brewery_search"
14
+ spec.license = "MIT"
15
+
16
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
17
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
18
+ if spec.respond_to?(:metadata)
19
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
20
+ else
21
+ raise "RubyGems 2.0 or newer is required to protect against " \
22
+ "public gem pushes."
23
+ end
24
+
25
+ # Specify which files should be added to the gem when it is released.
26
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
27
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
28
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
29
+ end
30
+ spec.bindir = "bin"
31
+ spec.executables = ["brewery-search"]
32
+ # spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
33
+ # spec.executables << "brewery-search"
34
+ spec.require_paths = ["lib"]
35
+
36
+ spec.add_development_dependency "bundler", "~> 1.16"
37
+ spec.add_development_dependency "rake", "~> 10.0"
38
+ spec.add_development_dependency "rspec", "~> 3.0"
39
+ spec.add_development_dependency "nokogiri", "~> 1.8", ">= 1.8.4"
40
+ spec.add_development_dependency "launchy", "~> 2.4", ">= 2.4.3"
41
+ spec.add_development_dependency "require_all", "~> 2.0"
42
+
43
+ end
@@ -0,0 +1,9 @@
1
+ require 'bundler'
2
+ Bundler.require
3
+
4
+ require_all 'lib'
5
+
6
+ require_relative '../lib/brewery_search/brewery.rb'
7
+ require_relative '../lib/brewery_search/cli.rb'
8
+ require_relative '../lib/brewery_search/scraper.rb'
9
+ require_relative '../lib/brewery_search/version.rb'
@@ -0,0 +1,4 @@
1
+ module BrewerySearch
2
+ end
3
+
4
+ require_relative '../config/environment.rb'
@@ -0,0 +1,63 @@
1
+ class BrewerySearch::Brewery
2
+ attr_accessor :name, :city, :state, :address, :phone, :type, :overview, :site_url, :external_site, :facebook_link, :twitter_link, :insta_link, :youtube_link
3
+ attr_reader :pages, :brewery_list
4
+
5
+ @@all = []
6
+
7
+ def self.create_from_state_scrape(input)
8
+ search_state = BrewerySearch::Scraper.scrape_by_state(input)
9
+ search_state.pages.each do |page|
10
+ page.css("table.breweries-list tbody tr").each do |info|
11
+ new_brewery = BrewerySearch::Brewery.new
12
+ new_brewery.name = info.css("td a.accented.hidden-mobile.bold").text.strip
13
+ new_brewery.city = info.css("td.hidden-mobile")[0].text.split(",")[0].strip
14
+ new_brewery.state = search_state.state
15
+ new_brewery.site_url = info.css("td a.accented.hidden-mobile.bold").attr("href").text.strip
16
+ new_brewery.type = info.css("td.hidden-mobile")[1].text.strip
17
+ @@all << new_brewery
18
+ search_state.brewery_list << new_brewery
19
+ end
20
+ end
21
+ @@all.sort_by! {|brewery| brewery.name}
22
+ end
23
+
24
+ #creates additional information from the breweries individual page entry only when called for
25
+ def create_profile_attributes
26
+ profile = BrewerySearch::Scraper.scrape_by_profile(self.site_url)
27
+
28
+ if profile.css("div #overview dl dd")[0].text.include?("JOB")
29
+ self.address = profile.css("div #overview dl dd")[3].css("a").attr("href").text.gsub(/\bhttps:.*=+./, '')
30
+ else
31
+ self.address = profile.css("div #overview dl dd")[2].css("a").attr("href").text.gsub(/\bhttps:.*=+./, '')
32
+ end
33
+
34
+ if profile.css("div #overview dl dd")[0].text.include?("JOB")
35
+ self.overview = profile.css("div #overview dl dd")[4].text
36
+ else
37
+ self.overview = profile.css("div #overview dl dd")[3].text
38
+ end
39
+
40
+ if profile.css("div.contact dt")[1].text == "Phone"
41
+ self.phone = profile.css("div.contact dd")[1].text
42
+ end
43
+
44
+ self.external_site = profile.css("div.contact a").attr("href").text
45
+
46
+ #grab social media links depending on what they have available
47
+ social_media = profile.css("div.contact ul.brewer-social-media li").each do |social|
48
+ if social.css("a").attr("href").text.include?("twitter")
49
+ self.twitter_link = social.css("a").attr("href").text
50
+ elsif social.css("a").attr("href").text.include?("facebook")
51
+ self.facebook_link = social.css("a").attr("href").text
52
+ elsif social.css("a").attr("href").text.include?("instagram")
53
+ self.insta_link = social.css("a").attr("href").text
54
+ elsif social.css("a").attr("href").text.include?("youtube")
55
+ self.youtube_link = social.css("a").attr("href").text
56
+ end
57
+ end
58
+ end
59
+
60
+ def self.all
61
+ @@all
62
+ end
63
+ end
@@ -0,0 +1,252 @@
1
+ #CLI Controller
2
+ class BrewerySearch::CLI
3
+ VALID_STATES = ["AL", "AK", "AZ", "AR", "CA", "CO", "CT", "DE", "FL", "GA", "HI", "ID", "IL", "IN", "IA", "KS", "KY", "LA", "ME", "MD", "MA", "MI", "MN", "MS", "MO", "MT", "NE", "NV", "NH", "NJ", "NM", "NY", "NC", "ND", "OH", "OK", "OR", "PA", "RI", "SC", "SD", "TN", "TX", "UT", "VT", "VA", "WA", "WV", "WI", "WY"]
4
+ @last_searched_state = nil
5
+ @last_searched_city = nil
6
+ @last_brew_list_searched = nil
7
+ @last_city_list_searched = nil
8
+
9
+ #launches the CLI and greets the user with a welcome screen, prompts user to enter a state to search
10
+ def welcome_screen
11
+ puts "*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*"
12
+ puts "AL ..,,,,,,... .. .. . .. MT"
13
+ puts "AK (# * NE"
14
+ puts "AZ ,# .','.'.'.'.'.'.'. , NV"
15
+ puts "AR .,,.,............. ,., NH"
16
+ puts "CA ,******,,,,,,,,,,,....***@, / NJ"
17
+ puts "CO ,/((#(#%##%####((///*,(((& NM"
18
+ puts "CT Welcome *((#(#############(((/((/# ,,. * NY"
19
+ puts "DE *(((###############(((((// *. NC"
20
+ puts "FL to *((((#######%#####(((/((/( .,. * ND"
21
+ puts "GA *((((#############(((/((// ,. ( OH"
22
+ puts "HI Brewery */((##############((((((/* *. , OK"
23
+ puts "ID *((((#############(((/((/* *. ( OR"
24
+ puts "IL Search *(((##############((((((/* *. . PA"
25
+ puts "IN *(((###############(((((/* *. ( RI"
26
+ puts "IA /(((###############(((((/* ,. * SC"
27
+ puts "KA /((########%%%#%###(((((/* ,. / SD"
28
+ puts "KY /((######%%%%%%%####((#(/* *,.* TN"
29
+ puts "LA /(#####%%%%%%%%%%###((#(/* *. / TX"
30
+ puts "ME /(####%%%%%%%%%%%###((#(%/ ,.. . UT"
31
+ puts "MD .((###%%%%%%%%%%%%%###(#(@ ...... VT"
32
+ puts "MA .((###%%%%%%%%%%%%%###(#(@ .... . VA"
33
+ puts "MI ,(###%%%%%%%%%%%%%%###(##/ WA"
34
+ puts "MN ,.*#//%/###(#(##(#//. ,,/ WV"
35
+ puts "MS , ./*** ,,,*./ WI"
36
+ puts "MO , /.. .**...// WY"
37
+ puts "*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*"
38
+ puts "* All information contained is referenced from BrewBound. *"
39
+ puts "* Type 'BrewBound' to visit them! *"
40
+ puts "*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*"
41
+ self.start
42
+ end
43
+
44
+ def start
45
+ input = nil
46
+
47
+ puts "Please enter the abbreviation for the state you'd like to search: "
48
+
49
+ input = gets.strip
50
+ @last_searched_state = input
51
+ if VALID_STATES.include?(input)
52
+ list_breweries(input)
53
+ elsif
54
+ puts "Invalid entry received."
55
+ self.start
56
+ elsif input == "exit"
57
+ self.quit
58
+ elsif input == "BrewBound"
59
+ Launchy.open ("https://www.brewbound.com/")
60
+ else
61
+ puts "Invalid entry received."
62
+ self.start
63
+ end
64
+ self.menu
65
+ end
66
+
67
+ #it will return a list of breweries from the state specified by the user, in alphabetical order by Brewery name
68
+ def list_breweries(input)
69
+ state_listing = nil
70
+
71
+ #checks the scraper class variable to ensure the state hasnt already been scraped to avoid unnecessary scraping
72
+ if BrewerySearch::Scraper.all.any? {|entry| entry.state == input}
73
+ state_listing = BrewerySearch::Brewery.all.select {|entry| entry.state == input}
74
+ @last_brew_list_searched = state_listing
75
+ else
76
+ state_listing = BrewerySearch::Brewery.create_from_state_scrape(input)
77
+ @last_brew_list_searched = state_listing
78
+ end
79
+
80
+ puts "Displaying results:"
81
+
82
+ state_listing.each_with_index {|brewery, index| puts "#{index + 1}. #{brewery.name} -- #{brewery.city}, #{brewery.state} -- #{brewery.type != "" ? brewery.type : "N/A" }"}
83
+ end
84
+
85
+ #will return a of breweries in the specified city
86
+ def breweries_by_city
87
+ input = nil
88
+
89
+ puts "Please enter the name of the city you would like to filter by:"
90
+ input = gets.strip
91
+
92
+ # state_listing = BrewerySearch::Brewery.all.select {|brewery| brewery.state == @last_searched_state}
93
+ state_listing = @last_brew_list_searched
94
+ city_listing = state_listing.select {|brewery| brewery.city == input && brewery.state == @last_searched_state}
95
+ @last_city_list_searched = city_listing
96
+
97
+ puts "Displaying results:"
98
+
99
+ city_listing.each_with_index {|brewery, index| puts "#{index + 1}. #{brewery.name} -- #{brewery.city}, #{brewery.state} -- #{brewery.type != "" ? brewery.type : "N/A" }"}
100
+
101
+ self.city_menu
102
+ end
103
+
104
+ def options_call
105
+ puts "\nPlease enter the number of a brewery for additional information.\nYou can type 'new search' to search again or 'exit' to quit."
106
+ puts "If you would like to filter by a specific city, please type 'city'."
107
+ end
108
+
109
+ #usuable only from #menu, has to be able to recall the previously used state
110
+ def state_result_call(input)
111
+ brewery = @last_brew_list_searched[input.to_i - 1]
112
+ puts "*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*"
113
+ puts "Brewery Name: #{brewery.name}"
114
+ puts "Brewery Address: #{brewery.address != nil ? brewery.address : "N/A"}"
115
+ puts "Brewery Location: #{brewery.city}, #{brewery.state}"
116
+ puts "Brewery Phone #: #{brewery.phone != nil ? brewery.phone : "N/A"}"
117
+ puts "Brewery Type: #{brewery.type != "" ? brewery.type : "N/A" }"
118
+ puts "Brewery Website: #{brewery.external_site != nil ? brewery.external_site : "N/A" }"
119
+ puts "Brewery Facebook: #{brewery.facebook_link != nil ? brewery.facebook_link : "N/A" }"
120
+ puts "Brewery Twitter: #{brewery.twitter_link != nil ? brewery.twitter_link : "N/A" }"
121
+ puts "Brewery Instagram: #{brewery.insta_link != nil ? brewery.insta_link : "N/A" }"
122
+ puts "Brewery Youtube: #{brewery.youtube_link != nil ? brewery.youtube_link : "N/A" }"
123
+ puts ""
124
+ puts "Brewery Overview: #{brewery.overview}"
125
+ puts "*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*"
126
+ puts "You can say 'Website', 'Facebook', 'Twitter', 'Instagram', or"
127
+ puts "'Youtube' to visit the page. Otherwise say 'menu' if you'd like"
128
+ puts "to return, or 'exit' if you'd like to quit."
129
+ end
130
+
131
+ #usable only from #city_menu, has to be able to recall the previously used city as to not interrupt flow
132
+ def city_result_call(input)
133
+ brewery = @last_city_list_searched[input.to_i - 1]
134
+ puts "*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*"
135
+ puts "Brewery Name: #{brewery.name}"
136
+ puts "Brewery Address: #{brewery.address != nil ? brewery.address : "N/A"}"
137
+ puts "Brewery Location: #{brewery.city}, #{brewery.state}"
138
+ puts "Brewery Phone #: #{brewery.phone != nil ? brewery.phone : "N/A"}"
139
+ puts "Brewery Type: #{brewery.type != "" ? brewery.type : "N/A" }"
140
+ puts "Brewery Website: #{brewery.external_site != nil ? brewery.external_site : "N/A" }"
141
+ puts "Brewery Facebook: #{brewery.facebook_link != nil ? brewery.facebook_link : "N/A" }"
142
+ puts "Brewery Twitter: #{brewery.twitter_link != nil ? brewery.twitter_link : "N/A" }"
143
+ puts "Brewery Instagram: #{brewery.insta_link != nil ? brewery.insta_link : "N/A" }"
144
+ puts "Brewery Youtube: #{brewery.youtube_link != nil ? brewery.youtube_link : "N/A" }"
145
+ puts ""
146
+ puts "Brewery Overview: #{brewery.overview}"
147
+ puts "*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*"
148
+ puts "You can say 'Website', 'Facebook', 'Twitter', 'Instagram', or"
149
+ puts "'Youtube' to visit the page. Otherwise say 'menu' if you'd like"
150
+ puts "to return, or 'exit' if you'd like to quit."
151
+ end
152
+
153
+ #it will provide the user with a list of options for the breweries returned by #list_breweries
154
+ def menu
155
+ self.options_call
156
+
157
+ input = nil
158
+ input = gets.strip
159
+
160
+ #has to use @last_brew_list_searched in order to continue to use state specific results
161
+ if input.to_i > 0
162
+ brewery = @last_brew_list_searched[input.to_i - 1]
163
+ brewery.create_profile_attributes
164
+
165
+ self.state_result_call(input)
166
+
167
+ input = gets.strip
168
+ if input == "Website"
169
+ Launchy.open("#{brewery.external_site}") {|exception| puts "Attempted to open #{brewery.external_site} but failed due to : #{exception}"}
170
+ self.menu
171
+ elsif input == "Facebook"
172
+ Launchy.open("#{brewery.facebook_link}") {|exception| puts "Attempted to open #{brewery.facebook_link} but failed due to : #{exception}"}
173
+ self.menu
174
+ elsif input == "Twitter"
175
+ Launchy.open("#{brewery.twitter_link}") {|exception| puts "Attempted to open #{brewery.twitter_link} but failed due to : #{exception}"}
176
+ self.menu
177
+ elsif input == "Instagram"
178
+ Launchy.open("#{brewery.insta_link}") {|exception| puts "Attempted to open #{brewery.insta_link} but failed due to : #{exception}"}
179
+ self.menu
180
+ elsif input == "Youtube"
181
+ Launchy.open("#{brewery.youtube_link}") {|exception| puts "Attempted to open #{brewery.youtube_link} but failed due to : #{exception}"}
182
+ self.menu
183
+ elsif input == "exit"
184
+ self.quit
185
+ else
186
+ self.menu
187
+ end
188
+ elsif input == "new search"
189
+ self.start
190
+ elsif input == "city"
191
+ self.breweries_by_city
192
+ elsif input == "exit"
193
+ self.quit
194
+ else
195
+ puts "Invalid entry received. Please select a number, 'city', 'new search', or 'exit'."
196
+ self.menu
197
+ end
198
+ end
199
+
200
+ #it will provide the user with a list of options for the breweries returned by #city_breweries
201
+ def city_menu
202
+ self.options_call
203
+
204
+ input = nil
205
+ input = gets.strip
206
+
207
+ #has to utilize @last_city_list_searched in order to continue to use city specific results
208
+ if input.to_i > 0
209
+ brewery = @last_city_list_searched[input.to_i - 1]
210
+ brewery.create_profile_attributes
211
+
212
+ self.city_result_call(input)
213
+
214
+ input = gets.strip
215
+ if input == "Website"
216
+ Launchy.open("#{brewery.external_site}") {|exception| puts "Attempted to open #{brewery.external_site} but failed due to : #{exception}"}
217
+ self.menu
218
+ elsif input == "Facebook"
219
+ Launchy.open("#{brewery.facebook_link}") {|exception| puts "Attempted to open #{brewery.facebook_link} but failed due to : #{exception}"}
220
+ self.menu
221
+ elsif input == "Twitter"
222
+ Launchy.open("#{brewery.twitter_link}") {|exception| puts "Attempted to open #{brewery.twitter_link} but failed due to : #{exception}"}
223
+ self.menu
224
+ elsif input == "Instagram"
225
+ Launchy.open("#{brewery.insta_link}") {|exception| puts "Attempted to open #{brewery.insta_link} but failed due to : #{exception}"}
226
+ self.menu
227
+ elsif input == "Youtube"
228
+ Launchy.open("#{brewery.youtube_link}") {|exception| puts "Attempted to open #{brewery.youtube_link} but failed due to : #{exception}"}
229
+ self.city_menu
230
+ elsif input == "exit"
231
+ self.quit
232
+ else
233
+ self.city_menu
234
+ end
235
+ elsif input == "new search"
236
+ self.start
237
+ elsif input == "city"
238
+ self.breweries_by_city
239
+ elsif input == "exit"
240
+ self.quit
241
+ else
242
+ puts "Invalid entry received. Please select a number, 'city', 'new search', or 'exit'."
243
+ self.city_menu
244
+ end
245
+ end
246
+
247
+ #it will terminate the program if the user so chooses
248
+ def quit
249
+ puts "Thank you for using Brewery Search. Have a great day!"
250
+ exit
251
+ end
252
+ end
@@ -0,0 +1,41 @@
1
+ require 'nokogiri'
2
+ require 'open-uri'
3
+
4
+ class BrewerySearch::Scraper
5
+ attr_accessor :state, :pages, :brewery_list
6
+
7
+ #will be a collection of scraped states that can be reused to prevent a state from potentially being re-scraped
8
+ @@all = []
9
+
10
+ #scrapes the state's page as specified by user and creates a collection from the table
11
+ def self.scrape_by_state(input)
12
+ state_object = BrewerySearch::Scraper.new
13
+ state_object.state = input
14
+ state_object.pages = []
15
+ state_object.brewery_list = []
16
+
17
+ page = 2
18
+
19
+ doc = Nokogiri::HTML(open("https://www.brewbound.com/mvc/Breweries/state/#{input}?displayOutOfBiz=False"))
20
+ state_object.pages << doc
21
+
22
+ #is able to scrape data from additional pages when applicable
23
+ while doc.css("table.breweries-list tfoot p.text-center").text.include?("Next") do
24
+ doc = Nokogiri::HTML(open("https://www.brewbound.com/mvc/Breweries/state/#{input}/page/#{page}?displayOutOfBiz=False"))
25
+ state_object.pages << doc
26
+ page += 1
27
+ end
28
+
29
+ @@all << state_object
30
+ state_object
31
+ end
32
+
33
+ #it will accept a url for a brewery's profile on the page, and scrape additional details to be displayed when requested
34
+ def self.scrape_by_profile(input)
35
+ doc = Nokogiri::HTML(open("https://www.brewbound.com#{input}"))
36
+ end
37
+
38
+ def self.all
39
+ @@all
40
+ end
41
+ end
@@ -0,0 +1,3 @@
1
+ module BrewerySearch
2
+ VERSION = "0.1.0"
3
+ end
Binary file
metadata ADDED
@@ -0,0 +1,162 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: brewery_search
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - btmccollum
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-09-08 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.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
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
+ - !ruby/object:Gem::Dependency
56
+ name: nokogiri
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.8'
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: 1.8.4
65
+ type: :development
66
+ prerelease: false
67
+ version_requirements: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - "~>"
70
+ - !ruby/object:Gem::Version
71
+ version: '1.8'
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: 1.8.4
75
+ - !ruby/object:Gem::Dependency
76
+ name: launchy
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: '2.4'
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: 2.4.3
85
+ type: :development
86
+ prerelease: false
87
+ version_requirements: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - "~>"
90
+ - !ruby/object:Gem::Version
91
+ version: '2.4'
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: 2.4.3
95
+ - !ruby/object:Gem::Dependency
96
+ name: require_all
97
+ requirement: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - "~>"
100
+ - !ruby/object:Gem::Version
101
+ version: '2.0'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - "~>"
107
+ - !ruby/object:Gem::Version
108
+ version: '2.0'
109
+ description: Allows a user to search for breweries by state by utilizing the www.brewbound.com
110
+ brewery database. A user can filter by city and obtain additional info about any
111
+ entry.
112
+ email:
113
+ - btmcco8@gmail.com
114
+ executables:
115
+ - brewery-search
116
+ extensions: []
117
+ extra_rdoc_files: []
118
+ files:
119
+ - ".rspec_status"
120
+ - CODE_OF_CONDUCT.md
121
+ - Gemfile
122
+ - Gemfile.lock
123
+ - LICENSE.txt
124
+ - README.md
125
+ - Rakefile
126
+ - bin/brewery-search
127
+ - bin/console
128
+ - bin/setup
129
+ - brewery_search.gemspec
130
+ - config/environment.rb
131
+ - lib/brewery_search.rb
132
+ - lib/brewery_search/brewery.rb
133
+ - lib/brewery_search/cli.rb
134
+ - lib/brewery_search/scraper.rb
135
+ - lib/brewery_search/version.rb
136
+ - pkg/brewery_search-0.1.0.gem
137
+ homepage: https://github.com/btmccollum/brewery_search
138
+ licenses:
139
+ - MIT
140
+ metadata:
141
+ allowed_push_host: https://rubygems.org
142
+ post_install_message:
143
+ rdoc_options: []
144
+ require_paths:
145
+ - lib
146
+ required_ruby_version: !ruby/object:Gem::Requirement
147
+ requirements:
148
+ - - ">="
149
+ - !ruby/object:Gem::Version
150
+ version: '0'
151
+ required_rubygems_version: !ruby/object:Gem::Requirement
152
+ requirements:
153
+ - - ">="
154
+ - !ruby/object:Gem::Version
155
+ version: '0'
156
+ requirements: []
157
+ rubyforge_project:
158
+ rubygems_version: 2.4.8
159
+ signing_key:
160
+ specification_version: 4
161
+ summary: A CLI brewery directory leveraging BrewBound
162
+ test_files: []