atp_rankings 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6efb8e02609c8482985104fc28da517e9ea7fa93
4
+ data.tar.gz: 75ebbcf003c904c2f92d92958c39c3f1e751d7bc
5
+ SHA512:
6
+ metadata.gz: b2363d4a139f9340d5c311a517f5ba47ad9357bbcaf46e5d49fac64c19c6dacb3351ebf09b62dbb5f5c1f9235bdf77397ab82f75bc104ec747d93769a67bc21d
7
+ data.tar.gz: ed9a3fb9659e62c2fcaaee7441e7ea1d25d9486e494760023a3dfabdce2ffe15d53f469045b9bb0cba04c734302a94c0c45078cfd141b62e1da92dd21537a49e
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
@@ -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 dijkstrascloud@gmail.com. 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
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in atp_rankings.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 evanscloud
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,49 @@
1
+ # Emirates Tennis ATP Rankings Singles Race to London Rubygem
2
+
3
+ This gem provides a current list of ranked singles tennis players who are competing to be part of the top 8. At the end of the season in November, these top 8 players for the current year qualify to enter the Barclays ATP World Tour Finals. This list allows a user to select a player and view a multitude of information regarding that athlete.
4
+
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'atp_rankings'
12
+ ```
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install atp_rankings
21
+
22
+
23
+ ## Dependencies
24
+
25
+ ```
26
+ 'nokogiri'
27
+ 'open-uri'
28
+ ```
29
+
30
+
31
+ ## Overview
32
+
33
+ This gem will provide a list of the current top 25 ranked tennis players in contention to qualify for the Barclays ATP World Tour Finals. User can select an athlete based on there Emirates ATP Race to London ranking to view there bio.
34
+
35
+
36
+ ## Development
37
+
38
+ 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.
39
+
40
+ 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).
41
+
42
+ ## Contributing
43
+
44
+ Bug reports and pull requests are welcome on GitHub at https://github.com/evanscloud/atp_rankings. 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.
45
+
46
+
47
+ ## License
48
+
49
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
@@ -0,0 +1,34 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'atp_rankings/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "atp_rankings"
8
+ spec.version = AtpRankings::VERSION
9
+ spec.authors = ["evanscloud"]
10
+ spec.email = ["dijkstrascloud@gmail.com"]
11
+
12
+ spec.summary = "Rubygem that provides info for the top 8 ATP singles athletes contending for the World Tour Finals."
13
+ spec.homepage = "https://github.com/evanscloud/atp-rankings-cli-gem"
14
+ spec.license = "MIT"
15
+
16
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
17
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
18
+ if spec.respond_to?(:metadata)
19
+ spec.metadata['allowed_push_host'] = 'https://rubygems.org'
20
+ else
21
+ raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
22
+ end
23
+
24
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
25
+ spec.bindir = "exe"
26
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
+ spec.require_paths = ["lib"]
28
+
29
+ spec.add_development_dependency "bundler", "~> 1.12"
30
+ spec.add_development_dependency "rake", "~> 10.0"
31
+ spec.add_development_dependency "pry", "~> 0"
32
+
33
+ spec.add_dependency "nokogiri", "~> 0"
34
+ end
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "atp_rankings"
5
+
6
+ AtpRankings::CLI.new.call
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "atp_rankings"
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
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,8 @@
1
+ require "nokogiri"
2
+ require "open-uri"
3
+ require "pry"
4
+
5
+ require_relative "../lib/atp_rankings/version"
6
+ require_relative "../lib/atp_rankings/cli"
7
+ require_relative "../lib/atp_rankings/athlete"
8
+ require_relative "../lib/atp_rankings/scraper"
@@ -0,0 +1 @@
1
+ require './config/environment'
@@ -0,0 +1,111 @@
1
+ class AtpRankings::Athlete
2
+ attr_accessor :name, :rank, :age, :points, :tourn_played, :url, :current_atp_rank, :turned_pro, :overall_record, :overall_titles, :overall_prize_money_earned, :orientation, :birthplace, :coach
3
+
4
+ @@all = []
5
+
6
+ def initialize(rank=nil, name=nil, age=nil, points=nil, tourn_played=nil, url=nil)
7
+ @rank = rank
8
+ @name = name
9
+ @age = age
10
+ @points = points
11
+ @tourn_played = tourn_played
12
+ @url = url
13
+ @@all << self
14
+ end
15
+
16
+ def self.all
17
+ @@all
18
+ end
19
+
20
+ def self.find(id)
21
+ self.all[id-1]
22
+ end
23
+
24
+
25
+ def self.find_by_name(name)
26
+ self.all.detect do |athlete|
27
+ athlete.name.downcase.strip == name.downcase.strip ||
28
+ athlete.name.split(" ").first.strip.downcase == name.downcase.strip
29
+ end
30
+ end
31
+
32
+ def current_atp_rank
33
+ array = []
34
+ info = doc.search("div.stat-value").text.strip
35
+ array = info.split("\n")
36
+ array[0].tr!("\t", "")
37
+ array[0].tr!("\r", "")
38
+ @atp_rank = array[0]
39
+ end
40
+
41
+ def turned_pro
42
+ array = []
43
+ info = doc.search("div.table-big-value").text.strip
44
+ array = info.split("\n")
45
+ array[6].tr!("\t", "")
46
+ array[6].tr!("\r", "")
47
+ @turned_pro = array[6]
48
+ end
49
+
50
+ def orientation
51
+ array = []
52
+ info = doc.search("div.table-value").text.strip
53
+ array = info.split("\n")
54
+ array[2].tr!("\t", "")
55
+ array[2].tr!("\r", "")
56
+ @orientation = array[2]
57
+ end
58
+
59
+ def birthplace
60
+ array = []
61
+ info = doc.search("div.table-value").text.strip
62
+ array = info.split("\n")
63
+ array[0].tr!("\t", "")
64
+ array[0].tr!("\r", "")
65
+ @birthplace = array[0]
66
+ end
67
+
68
+ def coach
69
+ array = []
70
+ info = doc.search("div.table-value").text.strip
71
+ array = info.split("\n")
72
+ if array[3] != nil
73
+ array[3].tr!("\t", "")
74
+ array[3].tr!("\r", "")
75
+ @coach = array[3]
76
+ else
77
+ @coach = "No Coach"
78
+ end
79
+ end
80
+
81
+ def overall_record
82
+ array = []
83
+ info = doc.search("div.stat-value").text.strip
84
+ array = info.split("\n")
85
+ array[12].tr!("\t", "")
86
+ array[12].tr!("\r", "")
87
+ @overall_record = array[12]
88
+ end
89
+
90
+ def overall_prize_money_earned
91
+ array = []
92
+ info = doc.search("div.stat-value").text.strip
93
+ array = info.split("\n")
94
+ array[16].tr!("\t", "")
95
+ array[16].tr!("\r", "")
96
+ @overall_prize_money_earned = array[16]
97
+ end
98
+
99
+ def overall_titles
100
+ array = []
101
+ info = doc.search("div.stat-value").text.strip
102
+ array = info.split("\n")
103
+ array[14].tr!("\t", "")
104
+ array[14].tr!("\r", "")
105
+ @overall_titles = array[14]
106
+ end
107
+
108
+ def doc
109
+ @doc ||= Nokogiri::HTML(open(self.url))
110
+ end
111
+ end
@@ -0,0 +1,60 @@
1
+ class AtpRankings::CLI
2
+ def call
3
+ AtpRankings::Scraper.new.create_athletes
4
+ puts "Welcome to Emirates ATP World Tour Race to London Rankings!"
5
+ puts "Below are the current top 25 players in contention for a top 8 spot."
6
+ puts ""
7
+ list_athletes
8
+ start
9
+ end
10
+
11
+ def start
12
+ puts ""
13
+ puts "Please select a player based on ranking number:"
14
+ input = gets.strip.to_i
15
+
16
+ if input != 0 && input.between?(1, 25)
17
+ athlete = AtpRankings::Athlete.find(input)
18
+ print_athlete(athlete)
19
+ else
20
+ puts "Hey, something went wrong... Let's try again."
21
+ start
22
+ end
23
+
24
+ puts ""
25
+ puts "View another player? Enter Y/N:"
26
+ input = gets.strip.downcase
27
+
28
+ if input == "y"
29
+ start
30
+ else
31
+ puts ""
32
+ puts "Idemo!"
33
+ puts ""
34
+ exit
35
+ end
36
+ end
37
+
38
+ def list_athletes
39
+ format = '%-12s %-25s %-8s %-10s %-10s'
40
+ puts format % ['RACE RANK', 'NAME', 'AGE', 'POINTS', 'TOURNAMENTS PLAYED']
41
+ AtpRankings::Athlete.all.each_with_index do |athlete, i|
42
+ puts format % [ athlete.rank, athlete.name, athlete.age, athlete.points, athlete.tourn_played ]
43
+ end
44
+ end
45
+
46
+ def print_athlete(athlete)
47
+ puts ""
48
+ puts "--- #{athlete.name} ----------------------"
49
+ puts ""
50
+ puts "Current ATP Rank: #{athlete.current_atp_rank}"
51
+ puts "Turned Pro: #{athlete.turned_pro}"
52
+ puts "Plays: #{athlete.orientation}"
53
+ puts "Birthplace: #{athlete.birthplace}"
54
+ puts "Coach(es): #{athlete.coach}"
55
+ puts "Current ATP Record: #{athlete.overall_record}"
56
+ puts "Total # of Titles Won: #{athlete.overall_titles}"
57
+ puts "Total Prize Money Earned: #{athlete.overall_prize_money_earned}"
58
+ puts ""
59
+ end
60
+ end
@@ -0,0 +1,25 @@
1
+ class AtpRankings::Scraper
2
+ def get_page
3
+ Nokogiri::HTML(open("http://www.atpworldtour.com/en/rankings/singles-race-to-london"))
4
+ end
5
+
6
+ def scrape_athletes_index
7
+ self.get_page.search("#singlesRanking")
8
+ end
9
+
10
+ def create_athletes
11
+ i = 1
12
+ while i < 26 do
13
+ scrape_athletes_index.each do |a|
14
+ athlete = AtpRankings::Athlete.new
15
+ athlete.rank = a.search("tr[#{i}] .rank-cell").text.strip
16
+ athlete.name = a.search("tr[#{i}] .player-cell").text.strip
17
+ athlete.age = a.search("tr[#{i}] .age-cell").text.strip
18
+ athlete.points = a.search("tr[#{i}] .points-cell").text.strip
19
+ athlete.tourn_played = a.search("tr[#{i}] .tourn-cell").text.strip
20
+ athlete.url = "http://www.atpworldtour.com" + a.search("tr[#{i}] .player-cell a").attr("href").text
21
+ i += 1
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,3 @@
1
+ module AtpRankings
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,118 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: atp_rankings
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - evanscloud
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-05-24 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.12'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.12'
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: pry
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '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: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description:
70
+ email:
71
+ - dijkstrascloud@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - CODE_OF_CONDUCT.md
78
+ - Gemfile
79
+ - LICENSE.txt
80
+ - README.md
81
+ - Rakefile
82
+ - atp_rankings.gemspec
83
+ - bin/atp_rankings
84
+ - bin/console
85
+ - bin/setup
86
+ - config/environment.rb
87
+ - lib/atp_rankings.rb
88
+ - lib/atp_rankings/athlete.rb
89
+ - lib/atp_rankings/cli.rb
90
+ - lib/atp_rankings/scraper.rb
91
+ - lib/atp_rankings/version.rb
92
+ homepage: https://github.com/evanscloud/atp-rankings-cli-gem
93
+ licenses:
94
+ - MIT
95
+ metadata:
96
+ allowed_push_host: https://rubygems.org
97
+ post_install_message:
98
+ rdoc_options: []
99
+ require_paths:
100
+ - lib
101
+ required_ruby_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ required_rubygems_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ requirements: []
112
+ rubyforge_project:
113
+ rubygems_version: 2.4.6
114
+ signing_key:
115
+ specification_version: 4
116
+ summary: Rubygem that provides info for the top 8 ATP singles athletes contending
117
+ for the World Tour Finals.
118
+ test_files: []