brewery_search 0.1.6 → 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +3 -1
- data/bin/brewery-search +2 -2
- data/bin/console +2 -2
- data/config/environment.rb +2 -0
- data/lib/brewery_search/brewery.rb +8 -63
- data/lib/brewery_search/cli.rb +77 -156
- data/lib/brewery_search/scraper.rb +73 -28
- data/lib/brewery_search/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 19a8043f1a54b3117e40be256e9dc55f09a25e4b
|
4
|
+
data.tar.gz: b325bad5b597d5e447d8f2049aab55846ff7908d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 032cf2965efc936ab7dcbe5b73361e8b9c09b20487a2e1b8b149d3740a9f41b94f94f65cacd1aeb114b56647b05f171cbe61438ab3ebdb10ab960ce52ce2c19c
|
7
|
+
data.tar.gz: 26b8334c1d8e6e84fc634364d1b6446cd46aa468463c01bbf2a2bf052090fad90f7c4c159057c7b4738af9953af761eed6b2fcf58b631b3a172952be3c7e310f
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
brewery_search (0.1.
|
4
|
+
brewery_search (0.1.7)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: http://rubygems.org/
|
@@ -21,6 +21,7 @@ GEM
|
|
21
21
|
method_source (~> 0.9.0)
|
22
22
|
public_suffix (3.0.3)
|
23
23
|
rake (10.5.0)
|
24
|
+
require_all (2.0.0)
|
24
25
|
rspec (3.8.0)
|
25
26
|
rspec-core (~> 3.8.0)
|
26
27
|
rspec-expectations (~> 3.8.0)
|
@@ -45,6 +46,7 @@ DEPENDENCIES
|
|
45
46
|
nokogiri (~> 1.8, >= 1.8.4)
|
46
47
|
pry (~> 0.11.3)
|
47
48
|
rake (~> 10.0)
|
49
|
+
require_all (~> 2.0)
|
48
50
|
rspec
|
49
51
|
|
50
52
|
BUNDLED WITH
|
data/bin/brewery-search
CHANGED
data/bin/console
CHANGED
data/config/environment.rb
CHANGED
@@ -1,73 +1,18 @@
|
|
1
1
|
class BrewerySearch::Brewery
|
2
|
-
attr_accessor :name, :city, :state, :address, :phone, :type, :overview, :site_url, :
|
3
|
-
attr_reader :pages, :brewery_list
|
2
|
+
attr_accessor :name, :city, :state, :address, :phone, :type, :overview, :site_url, :website, :facebook, :twitter, :instagram, :youtube
|
4
3
|
|
5
4
|
@@all = []
|
6
5
|
|
7
|
-
|
8
|
-
|
9
|
-
search_state = BrewerySearch::Scraper.scrape_by_state(input)
|
10
|
-
search_state.pages.each do |page|
|
11
|
-
page.css("table.breweries-list tbody tr").each do |info|
|
12
|
-
new_brewery = BrewerySearch::Brewery.new
|
13
|
-
new_brewery.name = info.css("td a.accented.hidden-mobile.bold").text.strip
|
14
|
-
new_brewery.city = info.css("td.hidden-mobile")[0].text.split(",")[0].strip
|
15
|
-
new_brewery.state = search_state.state
|
16
|
-
new_brewery.site_url = info.css("td a.accented.hidden-mobile.bold").attr("href").text.strip
|
17
|
-
new_brewery.type = info.css("td.hidden-mobile")[1].text.strip
|
18
|
-
@@all << new_brewery
|
19
|
-
search_state.brewery_list << new_brewery
|
20
|
-
end
|
21
|
-
end
|
22
|
-
@@all.sort_by! {|brewery| brewery.name}
|
6
|
+
def initialize
|
7
|
+
@@all << self
|
23
8
|
end
|
24
9
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
#determining address based one one of several formats the site can use
|
30
|
-
if (profile.css("div #overview dl dd dt").text.include?("PARENT") || profile.css("div #overview dl dd dt").text.include?("Founded")) && !!profile.css("div #overview dl dd")[0].text.match(/[0-9]/) == true
|
31
|
-
self.address = profile.css("div #overview dl dd")[3].css("a").attr("href").text.gsub(/\bhttps:.*=(?:,)?/, '')
|
32
|
-
elsif profile.css("div #overview dl dd dt").text.include?("PARENT") || profile.css("div #overview dl dd dt").text.include?("Founded")
|
33
|
-
self.address = profile.css("div #overview dl dd")[2].css("a").attr("href").text.gsub(/\bhttps:.*=(?:,)?/, '')
|
34
|
-
elsif profile.css("div #overview dl dd")[0].text.include?("JOB") && !!profile.css("div #overview dl dd")[0].text.match(/[0-9]/) == true
|
35
|
-
self.address = profile.css("div #overview dl dd")[3].css("a").attr("href").text.gsub(/\bhttps:.*=(?:,)?/, '')
|
36
|
-
else
|
37
|
-
self.address = profile.css("div #overview dl dd")[2].css("a").attr("href").text.gsub(/\bhttps:.*=(?:,)?/, '')
|
38
|
-
end
|
39
|
-
|
40
|
-
#determining overview based on one of several formats the site can use
|
41
|
-
if (profile.css("div #overview dl dd dt").text.include?("PARENT") || profile.css("div #overview dl dd dt").text.include?("Founded")) && !!profile.css("div #overview dl dd")[0].text.match(/[0-9]/) == true
|
42
|
-
self.overview = profile.css("div #overview dl dd")[4].text
|
43
|
-
elsif profile.css("div #overview dl dd dt").text.include?("PARENT") || profile.css("div #overview dl dd dt").text.include?("Founded")
|
44
|
-
self.overview = profile.css("div #overview dl dd")[3].text
|
45
|
-
elsif profile.css("div #overview dl dd")[0].text.include?("JOB") && !!profile.css("div #overview dl dd")[0].text.match(/[0-9]/) == true
|
46
|
-
self.overview = profile.css("div #overview dl dd")[4].text
|
47
|
-
else
|
48
|
-
self.overview = profile.css("div #overview dl dd")[3].text
|
49
|
-
end
|
50
|
-
|
51
|
-
#determine phone number
|
52
|
-
if profile.css("div.contact dt")[1].text == "Phone"
|
53
|
-
self.phone = profile.css("div.contact dd")[1].text
|
54
|
-
end
|
10
|
+
def self.find_by_state(state_input)
|
11
|
+
self.all.select {|entry| entry.state == state_input}
|
12
|
+
end
|
55
13
|
|
56
|
-
|
57
|
-
self.
|
58
|
-
|
59
|
-
#grab social media links depending on what they have available
|
60
|
-
social_media = profile.css("div.contact ul.brewer-social-media li").each do |social|
|
61
|
-
if social.css("a").attr("href").text.include?("twitter")
|
62
|
-
self.twitter_link = social.css("a").attr("href").text
|
63
|
-
elsif social.css("a").attr("href").text.include?("facebook")
|
64
|
-
self.facebook_link = social.css("a").attr("href").text
|
65
|
-
elsif social.css("a").attr("href").text.include?("instagram")
|
66
|
-
self.insta_link = social.css("a").attr("href").text
|
67
|
-
elsif social.css("a").attr("href").text.include?("youtube")
|
68
|
-
self.youtube_link = social.css("a").attr("href").text
|
69
|
-
end
|
70
|
-
end
|
14
|
+
def self.find_by_city(city_input)
|
15
|
+
self.all.select {|entry| entry.city == city_input}
|
71
16
|
end
|
72
17
|
|
73
18
|
def self.all
|
data/lib/brewery_search/cli.rb
CHANGED
@@ -1,10 +1,6 @@
|
|
1
|
-
|
1
|
+
require 'pry'
|
2
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
|
3
|
+
VALID_STATES = ["AL", "AK", "AZ", "AR", "CA", "CO", "CT", "DC", "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"]
|
8
4
|
|
9
5
|
#launches the CLI and greets the user with a welcome screen, prompts user to enter a state to search
|
10
6
|
def welcome_screen
|
@@ -42,136 +38,87 @@ class BrewerySearch::CLI
|
|
42
38
|
end
|
43
39
|
|
44
40
|
def start
|
45
|
-
|
46
|
-
|
47
|
-
puts "Please enter the abbreviation for the state you'd like to search: "
|
41
|
+
puts "Please enter the abbreviation for the state you'd like to search:"
|
48
42
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
43
|
+
@last_searched_state = gets.strip.upcase
|
44
|
+
|
45
|
+
if VALID_STATES.include?(@last_searched_state)
|
46
|
+
self.list_breweries(@last_searched_state)
|
47
|
+
elsif @last_searched_state.downcase == "exit"
|
48
|
+
self.quit
|
49
|
+
elsif @last_searched_state.downcase == "brewbound"
|
50
|
+
Launchy.open("https://www.brewbound.com/")
|
51
|
+
self.start
|
52
|
+
else
|
53
|
+
puts "Invalid entry received."
|
54
|
+
self.start
|
55
|
+
end
|
56
|
+
self.menu
|
62
57
|
end
|
63
58
|
|
64
59
|
#it will return a list of breweries from the state specified by the user, in alphabetical order by Brewery name
|
65
|
-
def list_breweries(
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
@
|
72
|
-
else
|
73
|
-
BrewerySearch::Brewery.create_from_state_scrape(input)
|
74
|
-
state_listing = BrewerySearch::Brewery.all.select {|entry| entry.state == input}
|
75
|
-
@last_brew_list_searched = state_listing
|
60
|
+
def list_breweries(state_input)
|
61
|
+
#checking to ensure we have not already scraped the state being searched
|
62
|
+
if BrewerySearch::Brewery.find_by_state(state_input) != []
|
63
|
+
@last_search = BrewerySearch::Brewery.find_by_state(state_input)
|
64
|
+
else
|
65
|
+
BrewerySearch::Scraper.scrape_state(state_input)
|
66
|
+
@last_search = BrewerySearch::Brewery.find_by_state(state_input)
|
76
67
|
end
|
77
|
-
|
78
|
-
puts "Displaying results:"
|
79
68
|
|
80
|
-
|
69
|
+
puts "Displaying results:"
|
70
|
+
puts ""
|
71
|
+
@last_search.each.with_index {|brewery, index| puts "#{index + 1}. #{brewery.name} -- #{brewery.city}, #{brewery.state} -- #{brewery.type != "" ? brewery.type : "N/A" }"}
|
81
72
|
end
|
82
73
|
|
83
|
-
#will return a of breweries in the specified city
|
74
|
+
#will return a list of breweries in the specified city
|
84
75
|
def breweries_by_city
|
85
|
-
|
86
|
-
|
76
|
+
city_input = nil
|
87
77
|
puts "Please enter the name of the city you would like to filter by:"
|
88
|
-
|
89
|
-
|
90
|
-
# state_listing = BrewerySearch::Brewery.all.select {|brewery| brewery.state == @last_searched_state}
|
91
|
-
state_listing = @last_brew_list_searched
|
92
|
-
city_listing = state_listing.select {|brewery| brewery.city == input && brewery.state == @last_searched_state}
|
93
|
-
@last_city_list_searched = city_listing
|
78
|
+
city_input = gets.strip.downcase.split.map{|word| word.capitalize}.join(' ')
|
94
79
|
|
95
|
-
|
96
|
-
|
97
|
-
city_listing.each_with_index {|brewery, index| puts "#{index + 1}. #{brewery.name} -- #{brewery.city}, #{brewery.state} -- #{brewery.type != "" ? brewery.type : "N/A" }"}
|
80
|
+
@last_search = BrewerySearch::Brewery.find_by_city(city_input)
|
98
81
|
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
def options_call
|
103
|
-
puts "\nPlease enter the number of a brewery for additional information.\nYou can type 'new search' to search again or 'exit' to quit."
|
104
|
-
puts "If you would like to filter by a specific city, please type 'city'."
|
105
|
-
end
|
106
|
-
|
107
|
-
#usuable only from #menu, serves to correctly fork for state searches
|
108
|
-
def state_result_call(input)
|
109
|
-
brewery = @last_brew_list_searched[input.to_i - 1]
|
110
|
-
self.ind_brewery_info(brewery)
|
111
|
-
end
|
82
|
+
puts "Displaying results:"
|
83
|
+
@last_search.each.with_index {|brewery, index| puts "#{index + 1}. #{brewery.name} -- #{brewery.city}, #{brewery.state} -- #{brewery.type != "" ? brewery.type : "N/A" }"}
|
112
84
|
|
113
|
-
|
114
|
-
def city_result_call(input)
|
115
|
-
brewery = @last_city_list_searched[input.to_i - 1]
|
116
|
-
self.ind_brewery_info(brewery)
|
85
|
+
self.menu
|
117
86
|
end
|
118
87
|
|
119
|
-
#
|
120
|
-
def ind_brewery_info(brewery)
|
121
|
-
puts "*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*"
|
122
|
-
puts "Brewery Name: #{brewery.name}"
|
123
|
-
puts "Brewery Address: #{brewery.address != nil ? brewery.address : "N/A"}"
|
124
|
-
puts "Brewery Location: #{brewery.city}, #{brewery.state}"
|
125
|
-
puts "Brewery Phone #: #{brewery.phone != nil ? brewery.phone : "N/A"}"
|
126
|
-
puts "Brewery Type: #{brewery.type != "" ? brewery.type : "N/A" }"
|
127
|
-
puts "Brewery Website: #{brewery.external_site != nil ? brewery.external_site : "N/A" }"
|
128
|
-
puts "Brewery Facebook: #{brewery.facebook_link != nil ? brewery.facebook_link : "N/A" }"
|
129
|
-
puts "Brewery Twitter: #{brewery.twitter_link != nil ? brewery.twitter_link : "N/A" }"
|
130
|
-
puts "Brewery Instagram: #{brewery.insta_link != nil ? brewery.insta_link : "N/A" }"
|
131
|
-
puts "Brewery Youtube: #{brewery.youtube_link != nil ? brewery.youtube_link : "N/A" }"
|
132
|
-
puts ""
|
133
|
-
puts "Brewery Overview: #{brewery.overview}"
|
134
|
-
puts "*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*"
|
135
|
-
puts "You can say 'Website', 'Facebook', 'Twitter', 'Instagram', or"
|
136
|
-
puts "'Youtube' to visit the page. Otherwise say 'menu' if you'd like"
|
137
|
-
puts "to return, or 'exit' if you'd like to quit."
|
138
|
-
end
|
139
|
-
|
140
|
-
#it will provide the user with a list of options for the breweries returned by #list_breweries
|
88
|
+
#creates flow for allowing user to select a specific brewery and obtain additional info or take other actions
|
141
89
|
def menu
|
142
|
-
|
90
|
+
puts "\nPlease enter the number of a brewery for additional information."
|
91
|
+
puts "To see a specific city, enter 'city', or enter 'relist' to show results from the state again."
|
92
|
+
puts "Otherwise, you can enter 'new search' to search again or 'exit' to quit."
|
143
93
|
|
144
94
|
input = nil
|
145
|
-
input = gets.strip
|
95
|
+
input = gets.strip.downcase
|
146
96
|
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
brewery
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
Launchy.open("#{brewery.
|
160
|
-
self.menu
|
161
|
-
elsif input == "Twitter"
|
162
|
-
Launchy.open("#{brewery.twitter_link}") {|exception| puts "Attempted to open #{brewery.twitter_link} but failed due to : #{exception}"}
|
163
|
-
self.menu
|
164
|
-
elsif input == "Instagram"
|
165
|
-
Launchy.open("#{brewery.insta_link}") {|exception| puts "Attempted to open #{brewery.insta_link} but failed due to : #{exception}"}
|
97
|
+
if (input.to_i > 0) && (input.to_i <= @last_search.size) #specific to a valid brewery selection
|
98
|
+
brewery = @last_search[input.to_i - 1] #uses @last_search to determine if user is at state or city level and to present the correct brewery and options
|
99
|
+
|
100
|
+
#checks to ensure the profile for the brewery being checked has not been scraped already
|
101
|
+
brewery.address != nil ? brewery : BrewerySearch::Scraper.scrape_profile(brewery)
|
102
|
+
|
103
|
+
#create display card for brewery
|
104
|
+
self.ind_brewery_info(brewery)
|
105
|
+
|
106
|
+
options_input = gets.strip.downcase
|
107
|
+
#control flow specific to #ind_brewery_info result
|
108
|
+
if brewery.instance_variables.any? {|attr| "@#{options_input}" == attr.to_s}
|
109
|
+
Launchy.open("#{brewery.send(options_input)}") {|exception| puts "Attempted to open #{brewery.send(options_input)} but failed due to : #{exception}"}
|
166
110
|
self.menu
|
167
|
-
elsif
|
168
|
-
Launchy.open("#{brewery.youtube_link}") {|exception| puts "Attempted to open #{brewery.youtube_link} but failed due to : #{exception}"}
|
111
|
+
elsif options_input == "menu"
|
169
112
|
self.menu
|
170
|
-
elsif
|
113
|
+
elsif options_input == "exit"
|
171
114
|
self.quit
|
172
115
|
else
|
116
|
+
puts "Invalid entry received. Returning to menu."
|
173
117
|
self.menu
|
174
118
|
end
|
119
|
+
elsif input == "relist"
|
120
|
+
self.list_breweries(@last_searched_state)
|
121
|
+
self.menu
|
175
122
|
elsif input == "new search"
|
176
123
|
self.start
|
177
124
|
elsif input == "city"
|
@@ -184,51 +131,25 @@ class BrewerySearch::CLI
|
|
184
131
|
end
|
185
132
|
end
|
186
133
|
|
187
|
-
#
|
188
|
-
def
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
Launchy.open("#{brewery.facebook_link}") {|exception| puts "Attempted to open #{brewery.facebook_link} but failed due to : #{exception}"}
|
207
|
-
self.city_menu
|
208
|
-
elsif input == "Twitter"
|
209
|
-
Launchy.open("#{brewery.twitter_link}") {|exception| puts "Attempted to open #{brewery.twitter_link} but failed due to : #{exception}"}
|
210
|
-
self.city_menu
|
211
|
-
elsif input == "Instagram"
|
212
|
-
Launchy.open("#{brewery.insta_link}") {|exception| puts "Attempted to open #{brewery.insta_link} but failed due to : #{exception}"}
|
213
|
-
self.city_menu
|
214
|
-
elsif input == "Youtube"
|
215
|
-
Launchy.open("#{brewery.youtube_link}") {|exception| puts "Attempted to open #{brewery.youtube_link} but failed due to : #{exception}"}
|
216
|
-
self.city_menu
|
217
|
-
elsif input == "exit"
|
218
|
-
self.quit
|
219
|
-
else
|
220
|
-
self.city_menu
|
221
|
-
end
|
222
|
-
elsif input == "new search"
|
223
|
-
self.start
|
224
|
-
elsif input == "city"
|
225
|
-
self.breweries_by_city
|
226
|
-
elsif input == "exit"
|
227
|
-
self.quit
|
228
|
-
else
|
229
|
-
puts "Invalid entry received. Please select a number, 'city', 'new search', or 'exit'."
|
230
|
-
self.city_menu
|
231
|
-
end
|
134
|
+
#returns an info sheet for a given brewery
|
135
|
+
def ind_brewery_info(brewery)
|
136
|
+
puts "\n*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*"
|
137
|
+
puts "Brewery Name: #{brewery.name}"
|
138
|
+
puts "Brewery Address: #{brewery.address != nil ? brewery.address : "N/A"}"
|
139
|
+
puts "Brewery Location: #{brewery.city}, #{brewery.state}"
|
140
|
+
puts "Brewery Phone #: #{brewery.phone != nil ? brewery.phone : "N/A"}"
|
141
|
+
puts "Brewery Type: #{brewery.type != "" ? brewery.type : "N/A" }"
|
142
|
+
puts "Brewery Website: #{brewery.website != nil ? brewery.website : "N/A" }"
|
143
|
+
puts "Brewery Facebook: #{brewery.facebook != nil ? brewery.facebook : "N/A" }"
|
144
|
+
puts "Brewery Twitter: #{brewery.twitter != nil ? brewery.twitter : "N/A" }"
|
145
|
+
puts "Brewery Instagram: #{brewery.instagram != nil ? brewery.instagram : "N/A" }"
|
146
|
+
puts "Brewery Youtube: #{brewery.youtube != nil ? brewery.youtube : "N/A" }"
|
147
|
+
puts ""
|
148
|
+
puts "Brewery Overview: #{brewery.overview.strip}"
|
149
|
+
puts "*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*"
|
150
|
+
puts "\nYou can say 'Website', 'Facebook', 'Twitter', 'Instagram', or"
|
151
|
+
puts "'Youtube' to visit the page. Otherwise say 'menu' if you'd like"
|
152
|
+
puts "to return, or 'exit' if you'd like to quit."
|
232
153
|
end
|
233
154
|
|
234
155
|
#it will terminate the program if the user so chooses
|
@@ -1,42 +1,87 @@
|
|
1
|
-
require 'nokogiri'
|
2
|
-
require 'open-uri'
|
3
|
-
|
4
1
|
class BrewerySearch::Scraper
|
5
|
-
|
2
|
+
|
3
|
+
def self.scrape_state(state_input)
|
4
|
+
search_result_pages = []
|
6
5
|
|
7
|
-
|
8
|
-
|
6
|
+
doc = Nokogiri::HTML(open("https://www.brewbound.com/mvc/Breweries/state/#{state_input}?displayOutOfBiz=False"))
|
7
|
+
search_result_pages << doc
|
9
8
|
|
10
|
-
|
11
|
-
|
12
|
-
state_object = BrewerySearch::Scraper.new
|
13
|
-
state_object.state = input
|
14
|
-
state_object.pages = []
|
15
|
-
state_object.brewery_list = []
|
16
|
-
|
9
|
+
#is able to scrape data from additional searrch result pages when applicable, all pages use same format for additional page
|
10
|
+
#results, and user input is injected into url
|
17
11
|
page = 2
|
18
|
-
|
19
|
-
#all state search pages use same HTML format, user input for state abbreviation is injected
|
20
|
-
doc = Nokogiri::HTML(open("https://www.brewbound.com/mvc/Breweries/state/#{input}?displayOutOfBiz=False"))
|
21
|
-
state_object.pages << doc
|
22
|
-
|
23
|
-
#is able to scrape data from additional pages when applicable, all pages use same format for additional page results, # and user input are injected
|
24
12
|
while doc.css("table.breweries-list tfoot p.text-center").text.include?("Next") do
|
25
|
-
doc = Nokogiri::HTML(open("https://www.brewbound.com/mvc/Breweries/state/#{
|
26
|
-
|
13
|
+
doc = Nokogiri::HTML(open("https://www.brewbound.com/mvc/Breweries/state/#{state_input}/page/#{page}?displayOutOfBiz=False"))
|
14
|
+
search_result_pages << doc
|
27
15
|
page += 1
|
28
16
|
end
|
29
17
|
|
30
|
-
|
31
|
-
|
18
|
+
#instantiates a new Brewery object for each entry
|
19
|
+
search_result_pages.each do |additional_page|
|
20
|
+
additional_page.css("table.breweries-list tbody tr").each do |tr|
|
21
|
+
new_brewery = BrewerySearch::Brewery.new
|
22
|
+
new_brewery.name = tr.css("td a.accented.hidden-mobile.bold").text.strip
|
23
|
+
new_brewery.city = tr.css("td.hidden-mobile")[0].text.split(",")[0].strip
|
24
|
+
new_brewery.state = state_input
|
25
|
+
new_brewery.site_url = tr.css("td a.accented.hidden-mobile.bold").attr("href").text.strip
|
26
|
+
new_brewery.type = tr.css("td.hidden-mobile")[1].text.strip
|
27
|
+
end
|
28
|
+
end
|
32
29
|
end
|
33
30
|
|
34
31
|
#it will accept a url for a brewery's profile on the page, and scrape additional details to be displayed when requested
|
35
|
-
def self.
|
36
|
-
|
37
|
-
|
32
|
+
def self.scrape_profile(brewery)
|
33
|
+
|
34
|
+
profile = Nokogiri::HTML(open("https://www.brewbound.com#{brewery.site_url}"))
|
35
|
+
|
36
|
+
#determining address based one one of several formats the site can use
|
37
|
+
if (profile.css("div #overview dl dd dt").text.include?("PARENT") || profile.css("div #overview dl dd dt").text.include?("Founded")) && !!profile.css("div #overview dl dd")[0].text.match(/[0-9]/) == true
|
38
|
+
brewery.address = profile.css("div #overview dl dd")[3].css("a").attr("href").text.gsub(/\bhttps:.*=(?:,)?/, '')
|
39
|
+
elsif profile.css("div #overview dl dd dt").text.include?("PARENT") || profile.css("div #overview dl dd dt").text.include?("Founded")
|
40
|
+
brewery.address = profile.css("div #overview dl dd")[2].css("a").attr("href").text.gsub(/\bhttps:.*=(?:,)?/, '')
|
41
|
+
elsif profile.css("div #overview dl dd")[0].text.include?("JOB") && !!profile.css("div #overview dl dd")[0].text.match(/[0-9]/) == true
|
42
|
+
brewery.address = profile.css("div #overview dl dd")[3].css("a").attr("href").text.gsub(/\bhttps:.*=(?:,)?/, '')
|
43
|
+
elsif profile.css("div #overview dl dd")[0].text.include?("JOB") && !!profile.css("div #overview dl dd")[3].text.match(/[0-9]/) == true
|
44
|
+
brewery.address = profile.css("div #overview dl dd")[3].css("a").attr("href").text.gsub(/\bhttps:.*=(?:,)?/, '')
|
45
|
+
elsif profile.css("div #overview dl dt")[2].text.include?("TYPE")
|
46
|
+
brewery.address = profile.css("div #overview dl dd")[3].css("a").attr("href").text.gsub(/\bhttps:.*=(?:,)?/, '')
|
47
|
+
else
|
48
|
+
brewery.address = profile.css("div #overview dl dd")[2].css("a").attr("href").text.gsub(/\bhttps:.*=(?:,)?/, '')
|
49
|
+
end
|
50
|
+
|
51
|
+
#determining overview based on one of several formats the site can use
|
52
|
+
if (profile.css("div #overview dl dd dt").text.include?("PARENT") || profile.css("div #overview dl dd dt").text.include?("Founded")) && !!profile.css("div #overview dl dd")[0].text.match(/[0-9]/) == true
|
53
|
+
brewery.overview = profile.css("div #overview dl dd")[4].text
|
54
|
+
elsif profile.css("div #overview dl dd dt").text.include?("PARENT") || profile.css("div #overview dl dd dt").text.include?("Founded")
|
55
|
+
brewery.overview = profile.css("div #overview dl dd")[3].text
|
56
|
+
elsif profile.css("div #overview dl dd")[0].text.include?("JOB") && !!profile.css("div #overview dl dd")[0].text.match(/[0-9]/) == true
|
57
|
+
brewery.overview = profile.css("div #overview dl dd")[4].text
|
58
|
+
elsif profile.css("div #overview dl dd")[0].text.include?("JOB") && !!profile.css("div #overview dl dd")[1].text.match(/[0-9]/) == true
|
59
|
+
brewery.overview = profile.css("div #overview dl dd")[4].text
|
60
|
+
elsif profile.css("div #overview dl dt")[2].text.include?("TYPE")
|
61
|
+
brewery.overview = profile.css("div #overview dl dd")[4].text
|
62
|
+
else
|
63
|
+
brewery.overview = profile.css("div #overview dl dd")[3].text
|
64
|
+
end
|
38
65
|
|
39
|
-
|
40
|
-
|
66
|
+
#determine phone number
|
67
|
+
if profile.css("div.contact dt")[1].text == "Phone"
|
68
|
+
brewery.phone = profile.css("div.contact dd")[1].text
|
69
|
+
end
|
70
|
+
|
71
|
+
#determine external website
|
72
|
+
brewery.website = profile.css("div.contact a").attr("href").text
|
73
|
+
|
74
|
+
#grab social media links depending on what they have available
|
75
|
+
social_media = profile.css("div.contact ul.brewer-social-media li").each do |social|
|
76
|
+
if social.css("a").attr("href").text.include?("twitter")
|
77
|
+
brewery.twitter = social.css("a").attr("href").text
|
78
|
+
elsif social.css("a").attr("href").text.include?("facebook")
|
79
|
+
brewery.facebook = social.css("a").attr("href").text
|
80
|
+
elsif social.css("a").attr("href").text.include?("instagram")
|
81
|
+
brewery.instagram = social.css("a").attr("href").text
|
82
|
+
elsif social.css("a").attr("href").text.include?("youtube")
|
83
|
+
brewery.youtube = social.css("a").attr("href").text
|
84
|
+
end
|
85
|
+
end
|
41
86
|
end
|
42
87
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: brewery_search
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- btmccollum
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-09-
|
11
|
+
date: 2018-09-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|