top-beers-cli-app 0.1.3

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: 749f5e85c631ea6b2ffc8815e9f7ef4b590347b5
4
+ data.tar.gz: 8469392b300fc36bdd8d5687ec0d4379296bacd0
5
+ SHA512:
6
+ metadata.gz: 439c9bcf917c34a32183199e0bd2dcd35136c50f76acace721801a81ce73931502100d37a23098d69a7b8ef29f6aab0b2a61244a250336ee39cdd4e6bf452812
7
+ data.tar.gz: f32218468e32c37f3a0592080a8450bac6dac901005dcd98265336ee1760910a7b0fd8157123188cdb5c917cc5df9053948e1c8a5fb1f1607e85ccea8ea2aa87
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,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.0
5
+ before_install: gem install bundler -v 1.13.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 TODO: Write your email address. 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,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in top-beers.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 TODO: Write your name
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,40 @@
1
+ # TopBeers
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/top-beers`. 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 'top-beers'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install top-beers
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]/top-beers. 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).
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/atom ADDED
File without changes
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "top-beers"
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
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/bin/top-beers ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "top-beers"
5
+
6
+ TopBeers::CLI.new.call
data/lib/top-beers.rb ADDED
@@ -0,0 +1,10 @@
1
+ require 'open-uri'
2
+ require 'nokogiri'
3
+ require 'colorize'
4
+
5
+ require_relative './top-beers/version'
6
+ require_relative './top-beers/beer'
7
+ require_relative './top-beers/cli'
8
+ require_relative './top-beers/scraper'
9
+ require_relative './top-beers/brewery'
10
+ require_relative './top-beers/style'
@@ -0,0 +1,24 @@
1
+ class TopBeers::Beer
2
+ attr_accessor :name, :style, :abv, :brewery, :url, :ba_score, :availability, :description
3
+
4
+ @@all = []
5
+
6
+ def initialize(name)
7
+ @name = name
8
+ @@all << self
9
+ end
10
+
11
+ def self.all
12
+ @@all
13
+ end
14
+
15
+ def style=(style)
16
+ @style = TopBeers::Style.find_or_create_by_name(style)
17
+ @style.beers << self
18
+ end
19
+
20
+ def brewery=(brewery)
21
+ @brewery = TopBeers::Brewery.find_or_create_by_name(brewery)
22
+ @brewery.beers << self
23
+ end
24
+ end
@@ -0,0 +1,47 @@
1
+ class TopBeers::Brewery
2
+ attr_accessor :location_1, :location_2, :website, :beers
3
+ attr_reader :name
4
+
5
+ @@all = []
6
+
7
+ def initialize(name)
8
+ @beers = []
9
+ @name = name
10
+ @@all << self
11
+ end
12
+
13
+ def self.find_or_create_by_name(name)
14
+ brewery = @@all.detect {|b| b.name.downcase == name.downcase}
15
+ if brewery.nil?
16
+ brewery = self.new(name)
17
+ end
18
+ brewery
19
+ end
20
+
21
+ def show_beers
22
+ puts "\n"+"-"*"#{@name}".length
23
+ puts "#{@name}"
24
+ puts "-"*"#{@name}".length
25
+ if @website.nil?
26
+ TopBeers::Scraper.scrape_details(@beers[0])
27
+ end
28
+ puts "Location".underline + ": #{self.location}"
29
+ puts "Website".underline + ": #{@website}"
30
+ puts "Beers in the top 250".underline + ":"
31
+ @beers.each.with_index(1) do |beer, i|
32
+ puts "#{i}. #{beer.name} - #{beer.style.name}"
33
+ end
34
+ end
35
+
36
+ def location
37
+ if @location_2.nil?
38
+ "#{@location_1}"
39
+ else
40
+ "#{@location_1}, #{@location_2}"
41
+ end
42
+ end
43
+
44
+ def self.all
45
+ @@all.sort_by! { |e| e.name }
46
+ end
47
+ end
@@ -0,0 +1,294 @@
1
+ class TopBeers::CLI
2
+ attr_accessor :beers, :breweries, :beer_list_count, :styles
3
+
4
+ def call
5
+ TopBeers::Scraper.scrape_beers
6
+ @beers = TopBeers::Beer.all
7
+ @breweries = TopBeers::Brewery.all
8
+ @styles = TopBeers::Style.all
9
+ @beer_list_count = 1
10
+ list_beers
11
+ beer_menu
12
+ end
13
+
14
+ def reset_beer_counter
15
+ @beer_list_count = 1
16
+ end
17
+ def list_beers
18
+ puts "\n---------------------------------------"
19
+ puts "Beer Advocate's Best Beers in the World"
20
+ puts "---------------------------------------"
21
+
22
+ if @beer_list_count > 25
23
+ i = @beer_list_count - 1
24
+ @beer_list_count = 1
25
+ i.times do
26
+ beer = @beers[beer_list_count - 1]
27
+ puts "#{@beer_list_count}. #{beer.name} - #{beer.brewery.name} - #{beer.style.name}"
28
+ @beer_list_count += 1
29
+ end
30
+ else
31
+ 25.times do
32
+ beer = @beers[beer_list_count - 1]
33
+ puts "#{beer_list_count}. #{beer.name} - #{beer.brewery.name} - #{beer.style.name}"
34
+ @beer_list_count += 1
35
+ end
36
+ end
37
+ end
38
+
39
+ def list_all_beers
40
+ @beers.each.with_index(1) do |beer, i|
41
+ puts "#{i}. #{beer.name} - #{beer.brewery.name} - #{beer.style.name}"
42
+ end
43
+ end
44
+
45
+ def more_beers
46
+ if @beer_list_count >= @beers.length
47
+ puts "There are no more beers to list"
48
+ else
49
+ 25.times do
50
+ beer = @beers[beer_list_count - 1]
51
+ puts "#{beer_list_count}. #{beer.name} - #{beer.brewery.name} - #{beer.style.name}"
52
+ @beer_list_count += 1
53
+ end
54
+ end
55
+ end
56
+
57
+ def list_breweries
58
+ puts "\n------------------------------------"
59
+ puts "Breweries with the World's Top Beers"
60
+ puts "------------------------------------"
61
+ puts
62
+ @breweries.each.with_index(1) do |brewery, i|
63
+ puts "#{i}. #{brewery.name}"
64
+ end
65
+ end
66
+
67
+ def list_styles
68
+ puts "\n------------------------------------"
69
+ puts "Styles with the World's Top Beers"
70
+ puts "------------------------------------"
71
+ puts
72
+ @styles.each.with_index(1) do |style, i|
73
+ puts "#{i}. #{style.name}"
74
+ end
75
+ end
76
+
77
+ def display_beer_detail(beer)
78
+ puts "\n"
79
+ puts "-"*"#{@beers.index(beer)+1}".length+"-"*"#{beer.name}".length+"--"
80
+ puts "#{@beers.index(beer)+1}. #{beer.name} \n"
81
+ puts "-"*"#{@beers.index(beer)+1}".length+"-"*"#{beer.name}".length+"--"
82
+ puts "Brewed by".underline + ": #{beer.brewery.name}\n"
83
+ puts "Location".underline + ": #{beer.brewery.location}"
84
+ puts "Website".underline + ": #{beer.brewery.website}"
85
+ puts "Style".underline + ": #{beer.style.name} \n"
86
+ puts "Alcohol by volume (ABV)".underline + ": #{beer.abv} \n"
87
+ puts "Beer Advocate Score".underline + ": #{beer.ba_score} \n"
88
+ puts "Availability".underline + ": #{beer.availability} \n"
89
+ puts "Description".underline + ": #{beer.description}"
90
+ end
91
+
92
+ def beer_menu
93
+ input = nil
94
+ while input != "exit"
95
+ puts "\n[Beer Menu]\nSelect a beer by " + "number".colorize(:light_red) + ", see " + "more".colorize(:light_red) + " beers, or type " + "help".colorize(:light_red) + " for a full list of commands." + " Type " + "exit".colorize(:light_red) + " to quit."
96
+ input = gets.strip.downcase
97
+
98
+ if input.to_i > 0 && input.to_i <= @beers.length
99
+ beer = @beers[input.to_i - 1]
100
+ if beer.description.nil?
101
+ TopBeers::Scraper.scrape_details(beer)
102
+ end
103
+ display_beer_detail(beer)
104
+ else
105
+ case input
106
+ when "list"
107
+ list_beers
108
+ when "beers"
109
+ list_beers
110
+ when "breweries"
111
+ list_breweries
112
+ brewery_menu
113
+ when "more"
114
+ more_beers
115
+ when "styles"
116
+ list_styles
117
+ style_menu
118
+ when "help"
119
+ help
120
+ when "all"
121
+ list_all_beers
122
+ when "reset"
123
+ reset_beer_counter
124
+ list_beers
125
+ when "exit"
126
+ abort(goodbye)
127
+ else
128
+ puts "\nNot sure what you want. Type " + "help".colorize(:light_red) + " for a full list of commands"
129
+ end
130
+ end
131
+ end
132
+ end
133
+
134
+ def brewery_menu
135
+ input = nil
136
+ while input != "exit"
137
+ puts "\n[Brewery Menu]\nSelect a brewery by " + "number".colorize(:light_red) + " or type " + "help".colorize(:light_red) + " for a full list of commands." + " Type " + "exit".colorize(:light_red) + " to quit."
138
+ input = gets.strip.downcase
139
+
140
+ if input.to_i > 0 && input.to_i <= @breweries.length
141
+ brewery = @breweries[input.to_i - 1]
142
+ brewery.show_beers
143
+ brewery_details_menu(brewery)
144
+ else
145
+ case input
146
+ when "list"
147
+ list_breweries
148
+ when "breweries"
149
+ list_breweries
150
+ when "beers"
151
+ list_beers
152
+ beer_menu
153
+ when "styles"
154
+ list_styles
155
+ style_menu
156
+ when "help"
157
+ help
158
+ when "exit"
159
+ abort(goodbye)
160
+ else
161
+ puts "\nNot sure what you want. Type " + "help".colorize(:light_red) + " for a full list of commands"
162
+ end
163
+ end
164
+ end
165
+ end
166
+
167
+ def brewery_details_menu(brewery)
168
+ input = nil
169
+ while input != "exit"
170
+ puts "\n[#{brewery.name} Menu]\nSelect a beer by " + "number".colorize(:light_red) + " or type " + "help".colorize(:light_red) + " for a full list of commands." + " Type " + "exit".colorize(:light_red) + " to quit."
171
+ input = gets.strip.downcase
172
+
173
+ if input.to_i > 0 && input.to_i <= brewery.beers.length
174
+ beer = brewery.beers[input.to_i - 1]
175
+ if beer.description.nil?
176
+ TopBeers::Scraper.scrape_details(beer)
177
+ end
178
+ display_beer_detail(beer)
179
+ else
180
+ case input
181
+ when "list"
182
+ brewery.show_beers
183
+ when "beers"
184
+ list_beers
185
+ beer_menu
186
+ when "help"
187
+ help
188
+ when "styles"
189
+ list_styles
190
+ style_menu
191
+ when "breweries"
192
+ list_breweries
193
+ brewery_menu
194
+ when "exit"
195
+ abort(goodbye)
196
+ else
197
+ puts "\nNot sure what you want. Type " + "help".colorize(:light_red) + " for a full list of commands"
198
+ end
199
+ end
200
+ end
201
+ end
202
+
203
+ def style_menu #TODO: refactor for TopBeers::Style
204
+ input = nil
205
+ while input != "exit"
206
+ puts "\n[Style Menu]\nSelect a style by " + "number".colorize(:light_red) + " or type " + "help".colorize(:light_red) + " for a full list of commands." + " Type " + "exit".colorize(:light_red) + " to quit."
207
+ input = gets.strip.downcase
208
+
209
+ if input.to_i > 0 && input.to_i <= @styles.length
210
+ style = @styles[input.to_i - 1]
211
+ style.show_beers
212
+ style_details_menu(style)
213
+ else
214
+ case input
215
+ when "list"
216
+ list_styles
217
+ when "styles"
218
+ list_styles
219
+ when "beers"
220
+ list_beers
221
+ beer_menu
222
+ when "breweries"
223
+ list_breweries
224
+ brewery_menu
225
+ when "help"
226
+ help
227
+ when "exit"
228
+ abort(goodbye)
229
+ else
230
+ puts "\nNot sure what you want. Type " + "help".colorize(:light_red) + " for a full list of commands"
231
+ end
232
+ end
233
+ end
234
+ end
235
+
236
+ def style_details_menu(style) #TODO: refactor for TopBeers::Style
237
+ input = nil
238
+ while input != "exit"
239
+ puts "\n[#{style.name} Menu]\nSelect a style by " + "number".colorize(:light_red) + " or type " + "help".colorize(:light_red) + " for a full list of commands." + " Type " + "exit".colorize(:light_red) + " to quit."
240
+ input = gets.strip.downcase
241
+
242
+ if input.to_i > 0 && input.to_i <= style.beers.length
243
+ beer = style.beers[input.to_i - 1]
244
+ if beer.description.nil?
245
+ TopBeers::Scraper.scrape_details(beer)
246
+ end
247
+ display_beer_detail(beer)
248
+ else
249
+ case input
250
+ when "list"
251
+ style.show_beers
252
+ when "beers"
253
+ list_beers
254
+ beer_menu
255
+ when "breweries"
256
+ list_breweries
257
+ brewery_menu
258
+ when "styles"
259
+ list_styles
260
+ style_menu
261
+ when "help"
262
+ help
263
+ when "exit"
264
+ abort(goodbye)
265
+ else
266
+ puts "\nNot sure what you want. Type " + "help".colorize(:light_red) + " for a full list of commands"
267
+ end
268
+ end
269
+ end
270
+ end
271
+
272
+ def help
273
+ puts "\n-------------------------"
274
+ puts "TopBeers List of Commands"
275
+ puts "-------------------------"
276
+ puts "Menu selection".underline + ":"
277
+ puts "beers".colorize(:light_red) + " displays the list of top beers, 25 at a time, up to 250"
278
+ puts "breweries".colorize(:light_red) + " displays the list of top breweries"
279
+ puts "styles".colorize(:light_red) + " displays the list of top styles"
280
+ puts "\nFrom the Beers menu".underline + ":"
281
+ puts "more".colorize(:light_red) + " lists 25 more beers from the current point in the list"
282
+ puts "all".colorize(:light_red) + " lists all 250 beers"
283
+ puts "reset".colorize(:light_red) + " shows the top 25 beers"
284
+ puts "\nFrom any menu".underline + ":"
285
+ puts "[number]".colorize(:light_red) + " selects an item with the corresponding number from the current menu"
286
+ puts "list".colorize(:light_red) + " displays the list of the current menu again"
287
+ puts "exit".colorize(:light_red) + " leaves the application"
288
+ end
289
+
290
+ def goodbye
291
+ "Thanks for using TopBeers!"
292
+ end
293
+
294
+ end
@@ -0,0 +1,45 @@
1
+ class TopBeers::Scraper
2
+ @@HOME = "https://www.beeradvocate.com"
3
+
4
+ def self.scrape_beers
5
+ doc = Nokogiri::HTML(open("https://www.beeradvocate.com/lists/top/"))
6
+ beers = doc.search(".hr_bottom_light[@align='left']")
7
+ self.create_beers(beers)
8
+ beers
9
+ end
10
+
11
+ def self.create_beers(beers)
12
+ beers.pop
13
+ i = 0
14
+ beers.each do |beer|
15
+ if i.even?
16
+ new_beer = TopBeers::Beer.new(beer.css("b").text)
17
+ new_beer.url = beer.children[0].attributes['href'].value
18
+ new_beer.brewery = "#{beer.css("#extendedInfo a")[0].text}"
19
+ new_beer.style = beer.css("#extendedInfo a")[1].text
20
+ if beer.css("#extendedInfo").children[3] != nil
21
+ new_beer.abv = beer.css("#extendedInfo").children[3].text[3, 10].chomp(" ABV")
22
+ end
23
+ end
24
+ i += 1
25
+ end
26
+ end
27
+
28
+ def self.scrape_details(beer)
29
+ doc = Nokogiri::HTML(open("https://www.beeradvocate.com"+beer.url))
30
+ beer.ba_score = doc.search(".ba-score").text
31
+
32
+ beer.brewery.location_1 = "#{doc.search('.break')[1].children[15].text}"
33
+ if beer.brewery.location_1 == "Belgium"
34
+ beer.availability = doc.search(".break")[1].children[35].text.strip
35
+ beer.brewery.website = "#{doc.search(".break")[1].children[17].text}"
36
+ beer.description = doc.search(".break")[1].children[42].text.gsub(/\n\t\t/, '')
37
+ else
38
+ beer.availability = doc.search(".break")[1].children[37].text.strip
39
+ beer.description = doc.search(".break")[1].children[44].text.gsub(/\n\t\t/, '')
40
+ beer.brewery.location_2 = "#{doc.search(".break")[1].children[17].text}"
41
+ beer.brewery.website = "#{doc.search('.break')[1].children[19].text}"
42
+ end
43
+ end
44
+
45
+ end
@@ -0,0 +1,33 @@
1
+ class TopBeers::Style
2
+ attr_accessor :beers
3
+ attr_reader :name
4
+
5
+ @@all = []
6
+
7
+ def initialize(name)
8
+ @beers = []
9
+ @name = name
10
+ @@all << self
11
+ end
12
+
13
+ def self.find_or_create_by_name(name)
14
+ style = @@all.detect {|b| b.name.downcase == name.downcase}
15
+ if style.nil?
16
+ style = self.new(name)
17
+ end
18
+ style
19
+ end
20
+
21
+ def show_beers
22
+ puts "\n"+"-"*"#{@name}".length
23
+ puts "#{@name}"
24
+ puts "-"*"#{@name}".length
25
+ @beers.each.with_index(1) do |beer, i|
26
+ puts "#{i}. #{beer.name} - #{beer.brewery.name}"
27
+ end
28
+ end
29
+
30
+ def self.all
31
+ @@all.sort_by! {|e| e.name}
32
+ end
33
+ end
@@ -0,0 +1,3 @@
1
+ module TopBeers
2
+ VERSION = "0.1.3"
3
+ end
data/top-beers.gemspec ADDED
@@ -0,0 +1,39 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'top-beers/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "top-beers-cli-app"
8
+ spec.version = TopBeers::VERSION
9
+ spec.authors = ["BJ Cantlupe"]
10
+ spec.email = ["bjcantlupe@gmail.com"]
11
+
12
+ spec.summary = %q{A CLI app for the world's top beers}
13
+ spec.description = %q{This app scrapes from Beer Advocates website to display the world's top 250 beers. The user can interact with the CLI to learn more information about each beer, including detailed descriptions, brewery information and ABV.}
14
+ spec.homepage = "https://github.com/BeejLuig/top-beers-cli-app"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ #if spec.respond_to?(:metadata)
20
+ # spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
21
+ #else
22
+ # raise "RubyGems 2.0 or newer is required to protect against " \
23
+ # "public gem pushes."
24
+ #end
25
+
26
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
27
+ f.match(%r{^(test|spec|features)/})
28
+ end
29
+ #spec.bindir = "exe"
30
+ spec.executables = ['top-beers']
31
+ spec.require_paths = ["lib", "lib/top-beers"]
32
+
33
+ spec.add_development_dependency "bundler", "~> 1.13"
34
+ spec.add_development_dependency "rake", "~> 10.0"
35
+ spec.add_development_dependency "rspec", "~> 3.0"
36
+ spec.add_development_dependency 'nokogiri', '~> 1.6', '>= 1.6.8'
37
+ spec.add_development_dependency 'colorize', '~> 0.8'
38
+
39
+ end
metadata ADDED
@@ -0,0 +1,144 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: top-beers-cli-app
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.3
5
+ platform: ruby
6
+ authors:
7
+ - BJ Cantlupe
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-10-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.13'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.13'
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.6'
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: 1.6.8
65
+ type: :development
66
+ prerelease: false
67
+ version_requirements: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - "~>"
70
+ - !ruby/object:Gem::Version
71
+ version: '1.6'
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: 1.6.8
75
+ - !ruby/object:Gem::Dependency
76
+ name: colorize
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: '0.8'
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: '0.8'
89
+ description: This app scrapes from Beer Advocates website to display the world's top
90
+ 250 beers. The user can interact with the CLI to learn more information about each
91
+ beer, including detailed descriptions, brewery information and ABV.
92
+ email:
93
+ - bjcantlupe@gmail.com
94
+ executables:
95
+ - top-beers
96
+ extensions: []
97
+ extra_rdoc_files: []
98
+ files:
99
+ - ".gitignore"
100
+ - ".rspec"
101
+ - ".travis.yml"
102
+ - CODE_OF_CONDUCT.md
103
+ - Gemfile
104
+ - LICENSE.txt
105
+ - README.md
106
+ - Rakefile
107
+ - atom
108
+ - bin/console
109
+ - bin/setup
110
+ - bin/top-beers
111
+ - lib/top-beers.rb
112
+ - lib/top-beers/beer.rb
113
+ - lib/top-beers/brewery.rb
114
+ - lib/top-beers/cli.rb
115
+ - lib/top-beers/scraper.rb
116
+ - lib/top-beers/style.rb
117
+ - lib/top-beers/version.rb
118
+ - top-beers.gemspec
119
+ homepage: https://github.com/BeejLuig/top-beers-cli-app
120
+ licenses:
121
+ - MIT
122
+ metadata: {}
123
+ post_install_message:
124
+ rdoc_options: []
125
+ require_paths:
126
+ - lib
127
+ - lib/top-beers
128
+ required_ruby_version: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ required_rubygems_version: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - ">="
136
+ - !ruby/object:Gem::Version
137
+ version: '0'
138
+ requirements: []
139
+ rubyforge_project:
140
+ rubygems_version: 2.6.7
141
+ signing_key:
142
+ specification_version: 4
143
+ summary: A CLI app for the world's top beers
144
+ test_files: []