best_whiskey 0.1.1
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 +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.travis.yml +4 -0
- data/CODE_OF_CONDUCT.md +49 -0
- data/Gemfile +8 -0
- data/LICENSE.txt +21 -0
- data/NOTES.md +115 -0
- data/README.md +38 -0
- data/Rakefile +6 -0
- data/best_whiskey.gemspec +33 -0
- data/bin/best_whiskey +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/best_whiskey.rb +8 -0
- data/lib/best_whiskey/cli.rb +116 -0
- data/lib/best_whiskey/contest_year.rb +35 -0
- data/lib/best_whiskey/scraper.rb +87 -0
- data/lib/best_whiskey/version.rb +3 -0
- data/lib/best_whiskey/whiskey.rb +56 -0
- metadata +108 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 46a68b10974c18eaf6c07ae22778557cb0e9197e
|
|
4
|
+
data.tar.gz: feeb9e4dbef35ab53470df4c24b713d4ff5d1514
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 96da02040c518eaa217f1465caa564df089d14709dff659c405db859f2c760f9a6d1b6026648fffe066b426e1e8e6f33db71f7f0696456fd303ccb79b89adbc0
|
|
7
|
+
data.tar.gz: 2e88d07d1a72b399bfb70c1bcebd489d2d23e3f8f7cb1672f6f6df57e58f168884ee227e9c9686eeeb9bbc322a9d30a3a84318bcf92e9467b0fdcd105f1304ac
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
|
@@ -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 TODO: Write your email address. 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
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/NOTES.md
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
best whiskeys gem
|
|
2
|
+
|
|
3
|
+
cli for whiskeys starting with
|
|
4
|
+
|
|
5
|
+
"Welcome to the whiskies of the year gem!"
|
|
6
|
+
"what year would you like to see? (2007 - )"
|
|
7
|
+
#if year not listed or available puts "sorry no whiskey winners listed for that year"
|
|
8
|
+
|
|
9
|
+
list categories for that year with number index
|
|
10
|
+
|
|
11
|
+
"please choose a category"
|
|
12
|
+
|
|
13
|
+
list whiskey with attributes
|
|
14
|
+
|
|
15
|
+
name, abv, category, style, country, producer, webiste?, description
|
|
16
|
+
|
|
17
|
+
prompt after every entry if they'd like to see more or exit
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
possible refactor notes for scraper:
|
|
21
|
+
|
|
22
|
+
class BestWhiskey::Scraper
|
|
23
|
+
attr_accessor :whiskey_urls
|
|
24
|
+
|
|
25
|
+
BASE_URL = 'http://www.worldwhiskiesawards.com/'
|
|
26
|
+
|
|
27
|
+
def initialize
|
|
28
|
+
@whiskey_urls = []
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def get_years_pages
|
|
32
|
+
base_doc = noko_open(BASE_URL+'2015/')
|
|
33
|
+
base_doc.css("nav.results li a").text.scan(/20\d\d/).map do |year|
|
|
34
|
+
BASE_URL+"#{year}"
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def get_whiskey_urls_main
|
|
39
|
+
get_years_pages.each do |url|
|
|
40
|
+
whiskey_urls << BASE_URL+noko_open(url).css('div.winner_main a').attribute('href').value
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def get_whiskey_urls_sub
|
|
45
|
+
get_years_pages.each do |url|
|
|
46
|
+
noko_open(url).css('div.winner_sub p.image a').each do |sub|
|
|
47
|
+
whiskey_urls << BASE_URL+sub.attribute('href').value
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def get_whiskey_urls
|
|
53
|
+
get_whiskey_urls_main
|
|
54
|
+
get_whiskey_urls_sub
|
|
55
|
+
whiskey_urls.uniq
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def make_whiskies
|
|
59
|
+
get_whiskey_urls.each do |url|
|
|
60
|
+
BestWhiskey::Whiskey.create_whiskey_from_url(w)
|
|
61
|
+
w = scrape_whiskey_from_url(url)
|
|
62
|
+
BestWhiskey::Whiskey.create_whiskey_from_scrp(w)
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def scrape_whiskey_from_url(url)
|
|
67
|
+
@whiskey = {}
|
|
68
|
+
@whiskey[:name] = scrape_name(url)
|
|
69
|
+
assign_award(url)
|
|
70
|
+
assign_winning_year(url)
|
|
71
|
+
assign_description(url)
|
|
72
|
+
|
|
73
|
+
noko_open(url).css("ul.details li").each do |details|
|
|
74
|
+
d = details.text.split(" ")
|
|
75
|
+
@whiskey[d.first.gsub(":","").downcase.to_sym] = d.drop(1).join(" ").downcase unless d.first == 'Website:'
|
|
76
|
+
end
|
|
77
|
+
@whiskey
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
def noko_open(url)
|
|
81
|
+
File.exists?(url.split("/").last)
|
|
82
|
+
|
|
83
|
+
# look for a local file for that url
|
|
84
|
+
# if present, open it with nokogiri
|
|
85
|
+
# otherwise actually open it from the internet and write it to disk (like in a db/) folder
|
|
86
|
+
|
|
87
|
+
Nokogiri::HTML(open(url))
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
def assign_award(url)
|
|
91
|
+
award = noko_open(url).css("span.award").map { |a| a.text.downcase unless a == nil}
|
|
92
|
+
@whiskey[:award] = award
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
def assign_winning_year(url)
|
|
96
|
+
year = noko_open(url).css("span.year").map { |y| y.text }
|
|
97
|
+
@whiskey[:winning_year] = year
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
def assign_name(url)
|
|
101
|
+
@whiskey[:name] = noko_open(url).css("section.details h1").text.downcase
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
def assign_description(url)
|
|
105
|
+
x = noko_open(url).css("div.award-wrapper p").first.text.strip
|
|
106
|
+
if x != ""
|
|
107
|
+
@whiskey[:description] = x
|
|
108
|
+
end
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
end
|
|
115
|
+
|
data/README.md
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# BestWhiskey
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
## Installation
|
|
5
|
+
|
|
6
|
+
Add this line to your application's Gemfile:
|
|
7
|
+
|
|
8
|
+
```ruby
|
|
9
|
+
gem 'best_whiskey'
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
And then execute:
|
|
13
|
+
|
|
14
|
+
$ bundle
|
|
15
|
+
|
|
16
|
+
Or install it yourself as:
|
|
17
|
+
|
|
18
|
+
$ gem install best_whiskey
|
|
19
|
+
|
|
20
|
+
## Usage
|
|
21
|
+
|
|
22
|
+
enter best_whiskey in the command line to get started
|
|
23
|
+
|
|
24
|
+
## Development
|
|
25
|
+
|
|
26
|
+
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.
|
|
27
|
+
|
|
28
|
+
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).
|
|
29
|
+
|
|
30
|
+
## Contributing
|
|
31
|
+
|
|
32
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/ryuichi7/best_whiskey. 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.
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
## License
|
|
36
|
+
|
|
37
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
|
38
|
+
|
data/Rakefile
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
+
require 'best_whiskey/version'
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |spec|
|
|
7
|
+
spec.name = "best_whiskey"
|
|
8
|
+
spec.version = BestWhiskey::VERSION
|
|
9
|
+
spec.authors = ["Brett Heenan"]
|
|
10
|
+
spec.email = ["brettrheenan@gmail.com"]
|
|
11
|
+
|
|
12
|
+
spec.summary = %q{A CLI gem that lists the best whiskies of the year}
|
|
13
|
+
spec.description = %q{Check out info and descriptions of the winner's of the best whisky of the year in several categories}
|
|
14
|
+
spec.homepage = "https://github.com/ryuichi7/best_whiskey.git"
|
|
15
|
+
spec.license = "MIT"
|
|
16
|
+
|
|
17
|
+
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
|
18
|
+
# delete this section to allow pushing this gem to any host.
|
|
19
|
+
if spec.respond_to?(:metadata)
|
|
20
|
+
spec.metadata['allowed_push_host'] = "https://rubygems.org"
|
|
21
|
+
else
|
|
22
|
+
raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
|
26
|
+
spec.bindir = "bin"
|
|
27
|
+
spec.executables = ["best_whiskey"]
|
|
28
|
+
spec.require_paths = ["lib"]
|
|
29
|
+
|
|
30
|
+
spec.add_development_dependency "bundler", "~> 1.11"
|
|
31
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
|
32
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
|
33
|
+
end
|
data/bin/best_whiskey
ADDED
data/bin/console
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require "bundler/setup"
|
|
4
|
+
require "best_whiskey"
|
|
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
data/lib/best_whiskey.rb
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
# CLI controller
|
|
2
|
+
class BestWhiskey::CLI
|
|
3
|
+
|
|
4
|
+
NEW_LINE = "\n"
|
|
5
|
+
|
|
6
|
+
LINE = ('-' * 12)
|
|
7
|
+
|
|
8
|
+
WELCOME_MESSAGE = "#{NEW_LINE}#{LINE} Welcome to the Best Whiskies of the Year CLI!" +
|
|
9
|
+
"#{LINE}#{NEW_LINE*2}"
|
|
10
|
+
|
|
11
|
+
ENTER_YEAR_MESSAGE = "#{NEW_LINE}Please enter the number of the year" +
|
|
12
|
+
" you'd like to explore. Enter 'e' at anytime to exit"
|
|
13
|
+
|
|
14
|
+
LIST_WINNERS_MESSAGE = "#{NEW_LINE}#{LINE} Here are the list of winners for "
|
|
15
|
+
|
|
16
|
+
ENTER_WHISKEY_MESSAGE = "#{NEW_LINE}Please enter the number of the whiskey you'd like to explore." +
|
|
17
|
+
" Enter 'e' at anytime to exit#{NEW_LINE*2}"
|
|
18
|
+
|
|
19
|
+
def call
|
|
20
|
+
puts NEW_LINE+"Please bear with us a moment while the gem loads..."
|
|
21
|
+
BestWhiskey::Scraper.new.make_whiskies
|
|
22
|
+
puts WELCOME_MESSAGE
|
|
23
|
+
list_years
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def list_years
|
|
28
|
+
puts ENTER_YEAR_MESSAGE
|
|
29
|
+
years_list
|
|
30
|
+
input = read
|
|
31
|
+
return if exit?(input)
|
|
32
|
+
if integer?(input) && input.to_i <= contest_years.size
|
|
33
|
+
whiskey_list(input)
|
|
34
|
+
else
|
|
35
|
+
invalid
|
|
36
|
+
list_years
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def whiskey_list(input)
|
|
41
|
+
winners_message(contest_years, input)
|
|
42
|
+
year = contest_years[input.to_i - 1]
|
|
43
|
+
year.whiskies.each_with_index { | whiskey, index | puts "#{index + 1}. #{whiskey.name.capitalize}" }
|
|
44
|
+
puts ENTER_WHISKEY_MESSAGE
|
|
45
|
+
input = read
|
|
46
|
+
return if exit?(input)
|
|
47
|
+
if integer?(input) && input.to_i <= year.whiskies.size
|
|
48
|
+
whiskey = year.whiskies[input.to_i - 1]
|
|
49
|
+
attributes.each do |a|
|
|
50
|
+
attribute = whiskey.send(a)
|
|
51
|
+
if a == :name
|
|
52
|
+
puts NEW_LINE+LINE+" #{attribute.capitalize} "+LINE+NEW_LINE*2
|
|
53
|
+
elsif a == :award
|
|
54
|
+
puts "#{a.capitalize}(s): #{attribute.join', '}"
|
|
55
|
+
else
|
|
56
|
+
puts "#{a.capitalize}: #{attribute.capitalize}" unless attribute == nil
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
next_step
|
|
60
|
+
else
|
|
61
|
+
invalid
|
|
62
|
+
whiskey_list(input)
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def next_step
|
|
67
|
+
puts NEW_LINE+"Would you like to see another whiskey? enter Y/N"
|
|
68
|
+
input = read
|
|
69
|
+
if input == 'y'
|
|
70
|
+
list_years
|
|
71
|
+
elsif input == 'n' || input == 'e'
|
|
72
|
+
puts NEW_LINE+"Thank you for visiting the Whiskey of the Year CLI!"+NEW_LINE*2
|
|
73
|
+
else
|
|
74
|
+
invalid
|
|
75
|
+
next_step
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
def years_list
|
|
80
|
+
contest_years.each_with_index do |year,index|
|
|
81
|
+
puts "#{index+1}. #{year.year}"
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
def exit?(input)
|
|
86
|
+
input == 'e'
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
def contest_years
|
|
90
|
+
@contest_years ||= BestWhiskey::ContestYear.all.sort! { |x,y| y.year <=> x.year }
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
def read
|
|
94
|
+
gets.strip.downcase
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
def attributes
|
|
98
|
+
BestWhiskey::Whiskey.attributes
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
def invalid
|
|
102
|
+
puts "\nSorry that's not a valid input"
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
def winners_message(years, input)
|
|
106
|
+
puts "#{LIST_WINNERS_MESSAGE}#{years[input.to_i - 1].year}" +
|
|
107
|
+
" #{LINE}#{NEW_LINE*2}"
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
def integer?(value)
|
|
111
|
+
value =~ /[\d]/
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
end
|
|
116
|
+
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
class BestWhiskey::ContestYear
|
|
2
|
+
attr_accessor :whiskies, :year
|
|
3
|
+
|
|
4
|
+
@@all = []
|
|
5
|
+
|
|
6
|
+
def initialize(year = nil)
|
|
7
|
+
@year = year
|
|
8
|
+
@whiskies = []
|
|
9
|
+
@@all << self
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def self.find_by_year(year)
|
|
13
|
+
self.all.detect { |w| w.year == year}
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def self.find_or_create_by_year(year)
|
|
17
|
+
self.find_by_year(year) || self.create(year)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def add_whiskey(whiskey)
|
|
21
|
+
@whiskies << whiskey
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def self.all
|
|
25
|
+
@@all
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def self.create(year)
|
|
29
|
+
self.new(year)
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
class BestWhiskey::Scraper
|
|
2
|
+
attr_accessor :whiskey_urls
|
|
3
|
+
|
|
4
|
+
BASE_URL = 'http://www.worldwhiskiesawards.com/'
|
|
5
|
+
|
|
6
|
+
def initialize
|
|
7
|
+
@whiskey_urls = []
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def get_years_pages
|
|
11
|
+
base_doc = noko_open(BASE_URL+'2015/')
|
|
12
|
+
base_doc.css("nav.results li a").text.scan(/20\d\d/).map do |year|
|
|
13
|
+
BASE_URL+"#{year}"
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def get_whiskey_urls_main
|
|
18
|
+
get_years_pages.each do |url|
|
|
19
|
+
whiskey_urls << BASE_URL+noko_open(url).css('div.winner_main a').attribute('href').value
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def get_whiskey_urls_sub
|
|
24
|
+
get_years_pages.each do |url|
|
|
25
|
+
noko_open(url).css('div.winner_sub p.image a').each do |sub|
|
|
26
|
+
whiskey_urls << BASE_URL+sub.attribute('href').value
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def get_whiskey_urls
|
|
32
|
+
get_whiskey_urls_main
|
|
33
|
+
get_whiskey_urls_sub
|
|
34
|
+
whiskey_urls.uniq
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def make_whiskies
|
|
38
|
+
get_whiskey_urls.each do |url|
|
|
39
|
+
w = scrape_whiskey_from_url(url)
|
|
40
|
+
BestWhiskey::Whiskey.create_whiskey_from_scrp(w)
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def scrape_whiskey_from_url(url)
|
|
45
|
+
@whiskey = {}
|
|
46
|
+
assign_name(url)
|
|
47
|
+
assign_award(url)
|
|
48
|
+
assign_winning_year(url)
|
|
49
|
+
assign_description(url)
|
|
50
|
+
|
|
51
|
+
noko_open(url).css("ul.details li").each do |details|
|
|
52
|
+
d = details.text.split(" ")
|
|
53
|
+
@whiskey[d.first.gsub(":","").downcase.to_sym] = d.drop(1).join(" ").downcase unless d.first == 'Website:'
|
|
54
|
+
end
|
|
55
|
+
@whiskey
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def noko_open(url)
|
|
59
|
+
Nokogiri::HTML(open(url))
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def assign_award(url)
|
|
63
|
+
award = noko_open(url).css("span.award").map { |a| a.text.downcase }
|
|
64
|
+
@whiskey[:award] = award
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def assign_winning_year(url)
|
|
68
|
+
year = noko_open(url).css("span.year").map { |y| y.text }
|
|
69
|
+
@whiskey[:winning_year] = year
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def assign_name(url)
|
|
73
|
+
@whiskey[:name] = noko_open(url).css("section.details h1").text.downcase
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
def assign_description(url)
|
|
77
|
+
x = noko_open(url).css("div.award-wrapper p").first.text.strip
|
|
78
|
+
if x != ""
|
|
79
|
+
@whiskey[:description] = x
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
end
|
|
87
|
+
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# This class ...
|
|
2
|
+
class BestWhiskey::Whiskey
|
|
3
|
+
|
|
4
|
+
attr_accessor :name,
|
|
5
|
+
:award,
|
|
6
|
+
:abv,
|
|
7
|
+
:category,
|
|
8
|
+
:style,
|
|
9
|
+
:country,
|
|
10
|
+
:producer,
|
|
11
|
+
:description,
|
|
12
|
+
:age,
|
|
13
|
+
:winning_year,
|
|
14
|
+
:vintage
|
|
15
|
+
|
|
16
|
+
@@all = []
|
|
17
|
+
|
|
18
|
+
def initialize(attribute_hash)
|
|
19
|
+
attribute_hash.each do | k, v |
|
|
20
|
+
self.send( "#{k}=", v )
|
|
21
|
+
end
|
|
22
|
+
@@all << self
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def self.create_whiskey_from_scrp(attribute_hash)
|
|
26
|
+
self.new(attribute_hash).tap do |whiskey|
|
|
27
|
+
whiskey.associate_year(whiskey.winning_year)
|
|
28
|
+
whiskey.winning_year.each { |w| w.add_whiskey(whiskey) }
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def associate_year(year)
|
|
33
|
+
y = year.map { |year| BestWhiskey::ContestYear.find_or_create_by_year(year) }
|
|
34
|
+
self.winning_year = y
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def self.all
|
|
38
|
+
@@all
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def self.attributes
|
|
42
|
+
[ :name,
|
|
43
|
+
:award,
|
|
44
|
+
:abv,
|
|
45
|
+
:category,
|
|
46
|
+
:style,
|
|
47
|
+
:country,
|
|
48
|
+
:producer,
|
|
49
|
+
:description,
|
|
50
|
+
:age,
|
|
51
|
+
:vintage
|
|
52
|
+
]
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
|
metadata
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: best_whiskey
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.1
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Brett Heenan
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2016-03-29 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: Check out info and descriptions of the winner's of the best whisky of
|
|
56
|
+
the year in several categories
|
|
57
|
+
email:
|
|
58
|
+
- brettrheenan@gmail.com
|
|
59
|
+
executables:
|
|
60
|
+
- best_whiskey
|
|
61
|
+
extensions: []
|
|
62
|
+
extra_rdoc_files: []
|
|
63
|
+
files:
|
|
64
|
+
- ".gitignore"
|
|
65
|
+
- ".rspec"
|
|
66
|
+
- ".travis.yml"
|
|
67
|
+
- CODE_OF_CONDUCT.md
|
|
68
|
+
- Gemfile
|
|
69
|
+
- LICENSE.txt
|
|
70
|
+
- NOTES.md
|
|
71
|
+
- README.md
|
|
72
|
+
- Rakefile
|
|
73
|
+
- best_whiskey.gemspec
|
|
74
|
+
- bin/best_whiskey
|
|
75
|
+
- bin/console
|
|
76
|
+
- bin/setup
|
|
77
|
+
- lib/best_whiskey.rb
|
|
78
|
+
- lib/best_whiskey/cli.rb
|
|
79
|
+
- lib/best_whiskey/contest_year.rb
|
|
80
|
+
- lib/best_whiskey/scraper.rb
|
|
81
|
+
- lib/best_whiskey/version.rb
|
|
82
|
+
- lib/best_whiskey/whiskey.rb
|
|
83
|
+
homepage: https://github.com/ryuichi7/best_whiskey.git
|
|
84
|
+
licenses:
|
|
85
|
+
- MIT
|
|
86
|
+
metadata:
|
|
87
|
+
allowed_push_host: https://rubygems.org
|
|
88
|
+
post_install_message:
|
|
89
|
+
rdoc_options: []
|
|
90
|
+
require_paths:
|
|
91
|
+
- lib
|
|
92
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
93
|
+
requirements:
|
|
94
|
+
- - ">="
|
|
95
|
+
- !ruby/object:Gem::Version
|
|
96
|
+
version: '0'
|
|
97
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
98
|
+
requirements:
|
|
99
|
+
- - ">="
|
|
100
|
+
- !ruby/object:Gem::Version
|
|
101
|
+
version: '0'
|
|
102
|
+
requirements: []
|
|
103
|
+
rubyforge_project:
|
|
104
|
+
rubygems_version: 2.4.6
|
|
105
|
+
signing_key:
|
|
106
|
+
specification_version: 4
|
|
107
|
+
summary: A CLI gem that lists the best whiskies of the year
|
|
108
|
+
test_files: []
|