PGA_Tour_Reader 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +8 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +24 -0
- data/LICENSE.txt +21 -0
- data/PGA_Tour_Reader.gemspec +37 -0
- data/README.md +43 -0
- data/Rakefile +2 -0
- data/bin/PGA_Tour_Reader +6 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/lib/PGA_Tour_Reader.rb +10 -0
- data/lib/PGA_Tour_Reader/cli.rb +38 -0
- data/lib/PGA_Tour_Reader/cli_helper.rb +44 -0
- data/lib/PGA_Tour_Reader/version.rb +3 -0
- data/lib/PGA_Tour_parser.rb +43 -0
- data/lib/PGA_Tour_scraper.rb +33 -0
- data/lib/PGA_season.rb +61 -0
- data/lib/PGA_tournament.rb +48 -0
- data/spec.md +6 -0
- metadata +107 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: ceef849d0cb2a835f53442ed7a27788d19cca3609fc6c4c027e8c31011843f67
|
4
|
+
data.tar.gz: 216e10d37856a44868ba699a6427f145e1fa6ff49cb86d36248d0d91d45a1792
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6157912ffdc4297137c06fd68fd963d5933bebb8a4176e4aa8e8d647451f7b10871ba565bb219c693ca71bd39a0d84f157c8ce5591ff006d80614bc3750f9fb0
|
7
|
+
data.tar.gz: 73446c0f19a7b0195e004fc1594dcfaf834e40da12d696dabed3815bc88c6ce142430009071b9cbdcd4c8f1a42010dda3cd0a424ba831fb69f41d8be10aa3bac
|
data/.gitignore
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -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 'taylor@thewilliams.net'. 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
data/Gemfile.lock
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
PGA_Tour_Reader (0.1.0)
|
5
|
+
nokogiri
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
mini_portile2 (2.3.0)
|
11
|
+
nokogiri (1.8.3)
|
12
|
+
mini_portile2 (~> 2.3.0)
|
13
|
+
rake (10.5.0)
|
14
|
+
|
15
|
+
PLATFORMS
|
16
|
+
ruby
|
17
|
+
|
18
|
+
DEPENDENCIES
|
19
|
+
PGA_Tour_Reader!
|
20
|
+
bundler (~> 1.16)
|
21
|
+
rake (~> 10.0)
|
22
|
+
|
23
|
+
BUNDLED WITH
|
24
|
+
1.16.2
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 'Taylor Williams'
|
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.
|
@@ -0,0 +1,37 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "PGA_Tour_Reader/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "PGA_Tour_Reader"
|
8
|
+
spec.version = PGATourReader::VERSION
|
9
|
+
spec.authors = ["'Taylor Williams'"]
|
10
|
+
spec.email = ["'taylor@thewilliams.net'"]
|
11
|
+
|
12
|
+
spec.summary = %q{PGATourReader scrapes information from the PGATour website and loads the information into a CLI}
|
13
|
+
spec.homepage = "https://github.com/Taylor-Williams/PGA_Tour_Reader"
|
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"] = "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 = "exe"
|
31
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
32
|
+
spec.require_paths = ["lib"]
|
33
|
+
|
34
|
+
spec.add_dependency "nokogiri"
|
35
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
36
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
37
|
+
end
|
data/README.md
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
# PGATourReader
|
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/PGA_Tour_Reader`. 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 'PGA_Tour_Reader'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install PGA_Tour_Reader
|
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. 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/'Taylor-Williams'/PGA_Tour_Reader. 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
|
+
## License
|
38
|
+
|
39
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
40
|
+
|
41
|
+
## Code of Conduct
|
42
|
+
|
43
|
+
Everyone interacting in the PGATourReader project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/'Taylor-Williams'/PGA_Tour_Reader/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/PGA_Tour_Reader
ADDED
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "PGA_Tour_Reader"
|
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
|
+
require "irb"
|
13
|
+
require 'nokogiri'
|
14
|
+
require 'open-uri'
|
15
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
require_relative "./PGA_Tour_Reader/version"
|
2
|
+
require_relative "./PGA_Tour_Reader/cli.rb"
|
3
|
+
require_relative "./PGA_tournament.rb"
|
4
|
+
require_relative "./PGA_season.rb"
|
5
|
+
require_relative "./PGA_Tour_scraper.rb"
|
6
|
+
require_relative "./PGA_Tour_parser.rb"
|
7
|
+
require_relative "./PGA_Tour_Reader/cli_helper.rb"
|
8
|
+
require 'date'
|
9
|
+
require 'open-uri'
|
10
|
+
require 'nokogiri'
|
@@ -0,0 +1,38 @@
|
|
1
|
+
class PGATourReader::CLI
|
2
|
+
|
3
|
+
def call
|
4
|
+
puts "Welcome to the PGA Tour Reader!"
|
5
|
+
prompt
|
6
|
+
end
|
7
|
+
|
8
|
+
def prompt
|
9
|
+
puts ""
|
10
|
+
puts "say \"list\" to list all the tournaments for the current PGA Tour season"
|
11
|
+
puts "for all the tournaments of a specific month type the month number (1-12)"
|
12
|
+
puts "for a specific tournament list any date it was played (mm/dd)"
|
13
|
+
puts "say \"exit\" to quit from PGA_Tour_Reader"
|
14
|
+
puts ""
|
15
|
+
get_requested_info(gets.strip.downcase)
|
16
|
+
end
|
17
|
+
|
18
|
+
def get_requested_info(request)
|
19
|
+
unless request == "exit"
|
20
|
+
case
|
21
|
+
when request == "list"
|
22
|
+
PGATourReader::PGA_Tour_Scraper.new()
|
23
|
+
PGATourReader::PGA_Season.get_season_by_year(Time.now.strftime("%Y")).list_all_for_season
|
24
|
+
when PGATourReader::CLI_Helper.is_month_day?(request)
|
25
|
+
PGATourReader::CLI_Helper.select_tournament(PGATourReader::PGA_Season.get_tournament(request))
|
26
|
+
when PGATourReader::CLI_Helper.is_month?(request)
|
27
|
+
puts ""
|
28
|
+
PGATourReader::PGA_Season.get_tournaments_by_month(request).each{|tournament| tournament.print_date_name}
|
29
|
+
puts ""
|
30
|
+
else
|
31
|
+
puts "I'm not sure what you said can you please give me a"
|
32
|
+
puts "request in the format requested, case insensitive."
|
33
|
+
end
|
34
|
+
prompt
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
class PGATourReader::CLI_Helper
|
2
|
+
|
3
|
+
def self.is_month_day?(request)
|
4
|
+
date = request.split("/") if /\A\d\d?\/\d\d?\z/ =~ request
|
5
|
+
date[0].to_i.between?(1,12) && date[1].to_i.between?(1,31) if date
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.is_month?(request)
|
9
|
+
/\A\d\d?\z/ =~ request && request.to_i.between?(1,12)
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.select_tournament(tournament)
|
13
|
+
if tournament
|
14
|
+
puts "you have selected the following tournament:"
|
15
|
+
puts ""
|
16
|
+
tournament.print_date_name
|
17
|
+
puts ""
|
18
|
+
puts "If you want a specific attribute type one of the below:"
|
19
|
+
tournament.list_attributes
|
20
|
+
puts ""
|
21
|
+
puts "If you want a list of all the information type \"list\""
|
22
|
+
puts "If you want to exit this menu type \"exit\""
|
23
|
+
puts ""
|
24
|
+
input = gets.strip.downcase
|
25
|
+
unless input == "exit"
|
26
|
+
case
|
27
|
+
when input == "list"
|
28
|
+
puts ""
|
29
|
+
tournament.print_attributes
|
30
|
+
puts ""
|
31
|
+
when tournament.is_attribute?(input)
|
32
|
+
puts ""
|
33
|
+
tournament.get_attribute(input)
|
34
|
+
puts ""
|
35
|
+
else
|
36
|
+
puts "please list a valid attribute or type \"list\" or \"exit\""
|
37
|
+
end
|
38
|
+
self.select_tournament(tournament)
|
39
|
+
end
|
40
|
+
else
|
41
|
+
puts "you didn't input the date of an official PGA tournament"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
class PGATourReader::PGA_Tour_Parser
|
2
|
+
|
3
|
+
#returns array of 2 dates, start at [0] end at [1]
|
4
|
+
def self.date_parser(month, days)
|
5
|
+
if /\d/ =~ month #when tourny weekend spans end of month
|
6
|
+
start_date = Date.parse("#{month} #{@year}")
|
7
|
+
end_date = Date.parse("#{days} #{@year}")
|
8
|
+
else #when tourny weekend starts and ends same month
|
9
|
+
days = days.split(" - ")
|
10
|
+
start_date = Date.parse("#{month} #{days[0]} #{@year}")
|
11
|
+
end_date = Date.parse("#{month} #{days[1]} #{@year}")
|
12
|
+
end
|
13
|
+
[self.set_year(start_date), self.set_year(end_date)]
|
14
|
+
end
|
15
|
+
|
16
|
+
#corrects the year for tournaments at the beginning of season
|
17
|
+
def self.set_year(date)
|
18
|
+
date.month.between?(10,12) ? date << 12 : date #new seasons start in oct (month 10)
|
19
|
+
end
|
20
|
+
|
21
|
+
#retuns hash of name, course, location (always) and purse, url if available
|
22
|
+
def self.attribute_parser(tournament_info)
|
23
|
+
attribute_text = tournament_info.children[4].text.split(/\s{2,}/)
|
24
|
+
attribute_text.shift
|
25
|
+
attributes = {
|
26
|
+
:name => tournament_info.children[1].children[0].text,
|
27
|
+
:url => self.url_parser(tournament_info),
|
28
|
+
:course => attribute_text[0].split(",")[0],
|
29
|
+
:location => "#{attribute_text[1]}#{attribute_text[2]}"[0..-2]
|
30
|
+
}
|
31
|
+
attributes[:purse] = "#{attribute_text[3].split(":")[1].strip}" if attribute_text.length == 4
|
32
|
+
attributes
|
33
|
+
end
|
34
|
+
|
35
|
+
#returns standardized url (if there is one) into https:// format
|
36
|
+
def self.url_parser(tournament_info)
|
37
|
+
url = tournament_info.children[1].attributes["href"]
|
38
|
+
if url
|
39
|
+
url.value.start_with?("/") ? url = "https://www.pgatour.com#{url.value}" : url = url.value
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
class PGATourReader::PGA_Tour_Scraper
|
2
|
+
|
3
|
+
attr_accessor :path, :year, :season
|
4
|
+
|
5
|
+
def initialize(year = Time.now.strftime("%Y"), path = "https://www.pgatour.com/tournaments/schedule.html")
|
6
|
+
@path = path
|
7
|
+
@year = year
|
8
|
+
@season = PGATourReader::PGA_Season.new(@year)
|
9
|
+
scrape_tour_page
|
10
|
+
end
|
11
|
+
|
12
|
+
#scrapes parses and zips all tournaments and their attributes for a season
|
13
|
+
def scrape_tour_page
|
14
|
+
page = Nokogiri::HTML(open("#{@path}"))
|
15
|
+
date_scraper(page) #instantiates all tournaments from this season by dates
|
16
|
+
tournament_attributes = attribute_scraper(page)
|
17
|
+
#zips together tournament attributes with tournament objects
|
18
|
+
@season.tournaments.each_with_index {|tournament, index| tournament.add_attributes(tournament_attributes[index])}
|
19
|
+
end
|
20
|
+
|
21
|
+
#scrapes all dates for a given season and returns an array of created Tournaments
|
22
|
+
def date_scraper(page)
|
23
|
+
page.css('.num-date').each do |date_info|
|
24
|
+
dates = PGATourReader::PGA_Tour_Parser.date_parser(date_info.children[1].children.text, date_info.children[3].children.text.strip)
|
25
|
+
@season.tournaments << PGATourReader::PGA_Tournament.new(dates[0], dates[1], @season)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
#scrapes name location course url and purse data and returns them in a hash
|
30
|
+
def attribute_scraper(page)
|
31
|
+
page.css(".tournament-text").map {|tournament_info| PGATourReader::PGA_Tour_Parser.attribute_parser(tournament_info)}
|
32
|
+
end
|
33
|
+
end
|
data/lib/PGA_season.rb
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
class PGATourReader::PGA_Season
|
2
|
+
|
3
|
+
attr_accessor :year, :tournaments
|
4
|
+
|
5
|
+
@@all = []
|
6
|
+
|
7
|
+
def initialize(year, tournaments = [])
|
8
|
+
@year = year
|
9
|
+
@tournaments = tournaments
|
10
|
+
save
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.all
|
14
|
+
@@all
|
15
|
+
end
|
16
|
+
|
17
|
+
def save
|
18
|
+
self.class.all << self
|
19
|
+
end
|
20
|
+
|
21
|
+
def list_all_for_season()
|
22
|
+
@tournaments.each do |tournament|
|
23
|
+
tournament.print_date_name
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.get_season_by_year(year)
|
28
|
+
season = self.all.detect{|season| season.year == year}
|
29
|
+
season ? season : PGATourReader::PGA_Tour_Scraper.new(year).season
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.get_tournaments_by_month(month_number, year = Time.now.strftime("%Y"))
|
33
|
+
season = self.get_season_by_year(year)
|
34
|
+
if season
|
35
|
+
season.tournaments.select {|tournament| tournament.start_date.month == month_number.to_i || tournament.end_date.month == month_number.to_i}
|
36
|
+
else
|
37
|
+
puts ""
|
38
|
+
puts "------------------------------------------------------------"
|
39
|
+
puts "I don't have the #{year} season on file let me load the data"
|
40
|
+
puts "------------------------------------------------------------"
|
41
|
+
puts ""
|
42
|
+
PGATourReader::PGA_Tour_Scraper.new(year)
|
43
|
+
self.get_tournaments_by_month(month_number, year)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def self.get_tournament(date, year = Time.now.strftime("%Y"))
|
48
|
+
dates = date.split("/")
|
49
|
+
puts ""
|
50
|
+
puts "your requested date is: #{dates[0]}, #{dates[1]}, #{year}"
|
51
|
+
puts ""
|
52
|
+
if Date.valid_date?(year.to_i, dates[0].to_i, dates[1].to_i)
|
53
|
+
tournament_date = Date.new(year.to_i, dates[0].to_i, dates[1].to_i)
|
54
|
+
got_tournament = self.get_tournaments_by_month(dates[0]).detect do |tournament|
|
55
|
+
(tournament_date <=> tournament.start_date) > -1 && (tournament_date <=> tournament.end_date) < 1
|
56
|
+
end
|
57
|
+
else
|
58
|
+
puts "that date is invalid, make sure to use the format of mm/dd"
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
class PGATourReader::PGA_Tournament
|
2
|
+
|
3
|
+
attr_accessor :start_date, :end_date, :season, :attributes, :purse, :name, :location, :winner, :cup_points, :url, :course, :winnings
|
4
|
+
|
5
|
+
def initialize(start_date, end_date, season, attributes = {})
|
6
|
+
@start_date = start_date
|
7
|
+
@end_date = end_date
|
8
|
+
@season = season
|
9
|
+
self.add_attributes(attributes)
|
10
|
+
end
|
11
|
+
|
12
|
+
#accepts hash of many tournament attributes and assigns them to self
|
13
|
+
def add_attributes(attributes)
|
14
|
+
@attributes = attributes
|
15
|
+
attributes.each {|key, value| self.send("#{key}=", value)}
|
16
|
+
end
|
17
|
+
|
18
|
+
#prints all attributes self has
|
19
|
+
def print_attributes
|
20
|
+
@attributes.each{|attribute, value| puts "#{attribute}: #{value}"}
|
21
|
+
end
|
22
|
+
|
23
|
+
#gets a single attribute's value
|
24
|
+
def get_attribute(attribute)
|
25
|
+
request = is_attribute?(attribute)
|
26
|
+
if request
|
27
|
+
puts "#{request} : #{@attributes[request]}"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
#checks to see if attribute this tournament contains and returns attributes' symbol
|
32
|
+
def is_attribute?(attribute)
|
33
|
+
@attributes.keys.detect{|key| key.to_s == attribute}
|
34
|
+
end
|
35
|
+
|
36
|
+
#lists all attributes self has
|
37
|
+
def list_attributes
|
38
|
+
puts ""
|
39
|
+
@attributes.keys[0..-2].each{|a| print "#{a}, "}
|
40
|
+
puts attributes.keys.last
|
41
|
+
end
|
42
|
+
|
43
|
+
#prints basic information about self in "2/2 - 2/6: Greenbriar Classic" format
|
44
|
+
def print_date_name()
|
45
|
+
puts "#{self.start_date} - #{self.end_date}: #{self.name}"
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
data/spec.md
ADDED
metadata
ADDED
@@ -0,0 +1,107 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: PGA_Tour_Reader
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- "'Taylor Williams'"
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-06-28 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: nokogiri
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.16'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.16'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
description:
|
56
|
+
email:
|
57
|
+
- "'taylor@thewilliams.net'"
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- CODE_OF_CONDUCT.md
|
64
|
+
- Gemfile
|
65
|
+
- Gemfile.lock
|
66
|
+
- LICENSE.txt
|
67
|
+
- PGA_Tour_Reader.gemspec
|
68
|
+
- README.md
|
69
|
+
- Rakefile
|
70
|
+
- bin/PGA_Tour_Reader
|
71
|
+
- bin/console
|
72
|
+
- bin/setup
|
73
|
+
- lib/PGA_Tour_Reader.rb
|
74
|
+
- lib/PGA_Tour_Reader/cli.rb
|
75
|
+
- lib/PGA_Tour_Reader/cli_helper.rb
|
76
|
+
- lib/PGA_Tour_Reader/version.rb
|
77
|
+
- lib/PGA_Tour_parser.rb
|
78
|
+
- lib/PGA_Tour_scraper.rb
|
79
|
+
- lib/PGA_season.rb
|
80
|
+
- lib/PGA_tournament.rb
|
81
|
+
- spec.md
|
82
|
+
homepage: https://github.com/Taylor-Williams/PGA_Tour_Reader
|
83
|
+
licenses:
|
84
|
+
- MIT
|
85
|
+
metadata: {}
|
86
|
+
post_install_message:
|
87
|
+
rdoc_options: []
|
88
|
+
require_paths:
|
89
|
+
- lib
|
90
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
91
|
+
requirements:
|
92
|
+
- - ">="
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '0'
|
95
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
96
|
+
requirements:
|
97
|
+
- - ">="
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '0'
|
100
|
+
requirements: []
|
101
|
+
rubyforge_project:
|
102
|
+
rubygems_version: 2.7.7
|
103
|
+
signing_key:
|
104
|
+
specification_version: 4
|
105
|
+
summary: PGATourReader scrapes information from the PGATour website and loads the
|
106
|
+
information into a CLI
|
107
|
+
test_files: []
|