espn-tennis-cli-app 0.0.1

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: 6f91784e839b06c08a9f6eff0df37e535054ef4d
4
+ data.tar.gz: e72e6ac544d89845e0bd76b5b9c5030a8657d5ec
5
+ SHA512:
6
+ metadata.gz: 3ca15b11755d03087bb248fbdd2c37468cde2e49836a9466cbdbe764244d53e3700cc9999044543cd6a3de8abe7995e2ece04e36ca4c1794eea51a5524c7cec6
7
+ data.tar.gz: b27b50eef9029ef3d96f030ddcf35a57b21800c24de3d6819e528404e08969845e5eeb4c120f583a5ef4e99ec3f7911f68541bf21e5dd114fae840a699f5c537
@@ -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,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 sophiavarella@gmail.com. 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 espn-tennis-cli-app.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2017 Sophia Varella
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 all
13
+ 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 THE
21
+ SOFTWARE.
@@ -0,0 +1,41 @@
1
+ # ESPN Tennis CLI
2
+
3
+ This gem installs a command line utility that can fetch the latest ATP/WTA rankings from the ESPN website.
4
+
5
+ It can also get additional information for individual Players from either the ATP/WTA rankings.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'espn-tennis-cli-app'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install espn-tennis-cli-app
22
+
23
+ ## Usage
24
+
25
+ Once the gem is installed you can run `espn-tennis` to interact with the CLI.
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 `espn-tennis-cli-app.gemspec`, 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/sophiav/espn-tennis-cli-app. 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).
41
+
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "require_all"
5
+ require_all "./lib"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ require "pry"
12
+ Pry.start
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ require_relative '../config/environment'
3
+
4
+ EspnTennisController.new.call
@@ -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,6 @@
1
+ require 'open-uri'
2
+ require 'require_all'
3
+ require 'nokogiri'
4
+
5
+ lib_path = File.expand_path('../../lib', __FILE__)
6
+ require_all lib_path
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "espn-tennis-cli-app"
7
+ spec.version = "0.0.1"
8
+ spec.authors = ["Sophia Varella"]
9
+ spec.email = ["sophiavarella@gmail.com"]
10
+
11
+ spec.summary = %q{ESPN Tennis rankings}
12
+ spec.description = %q{Gets ATP/WTA Rankings and player bios from the ESPN website}
13
+ spec.homepage = "https://github.com/sophiav/espn-tennis-cli-app"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
+ f.match(%r{^(test|spec|features)/})
18
+ end
19
+ spec.bindir = "bin"
20
+ spec.executables = ["espn-tennis"]
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_runtime_dependency "nokogiri", "~> 1.7"
24
+ spec.add_runtime_dependency "require_all", "~> 1.4"
25
+
26
+ spec.add_development_dependency "bundler", "~> 1.13"
27
+ spec.add_development_dependency "rake", "~> 12.0"
28
+ spec.add_development_dependency "pry", "~> 0.10"
29
+ end
@@ -0,0 +1,41 @@
1
+ class EspnTennisController
2
+ def initialize
3
+ puts "=" * 50
4
+ puts "ESPN Tennis Rankings"
5
+ puts "=" * 50
6
+ EspnTennisScraper.scrape_all_rankings
7
+ end
8
+
9
+ def call
10
+ puts "What tour would like see? (ATP/WTA)"
11
+
12
+ input = ""
13
+ while input != "exit"
14
+ input = gets.strip.downcase
15
+ if input == 'atp'
16
+ Rankings.print_atp_rankings
17
+ tour_type = 'atp'
18
+
19
+ elsif input == 'wta'
20
+ Rankings.print_wta_rankings
21
+ tour_type = 'wta'
22
+
23
+ elsif input.to_i > 0
24
+ Player.find_by_rank_and_tour(input, tour_type).player_bio
25
+ elsif input == "exit"
26
+ puts "Goodbye!"
27
+ else
28
+ player = Player.find_by_name(input)
29
+ if player
30
+ player.player_bio
31
+ else
32
+ puts "Could not find a player with that name. Please try again."
33
+ end
34
+ end
35
+
36
+ puts "You can enter the rank or player name to see more information about that player."
37
+ puts "(or type 'atp' or 'wta' to list those rankings)"
38
+
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,40 @@
1
+ class EspnTennisScraper
2
+ def self.scrape_all_rankings
3
+ self.scrape_atp_rankings
4
+ self.scrape_wta_rankings
5
+ end
6
+
7
+ def self.scrape(url, tour)
8
+ doc = Nokogiri::HTML(open(url))
9
+ player_rows = doc.css('.mod-content table tr[class*="player"]')
10
+
11
+ players = player_rows.map do |player_row|
12
+ rank = player_row.css('td')[0].text
13
+ name = player_row.css('td')[1].css('a').text
14
+ url = player_row.css('td')[1].css('a').attr('href').text
15
+ country = player_row.css('td')[2].css('img').attr('title').text
16
+ points = player_row.css('td')[4].text
17
+
18
+ player_hash = {
19
+ rank: rank,
20
+ name: name,
21
+ url: "http://www.espn.com#{url}",
22
+ country: country,
23
+ points: points,
24
+ tour: tour
25
+ }
26
+ # create a new player from the hash
27
+ player = Player.create_from_hash(player_hash)
28
+ end
29
+ end
30
+
31
+ private
32
+
33
+ def self.scrape_atp_rankings
34
+ self.scrape("http://www.espn.com/tennis/rankings", "atp")
35
+ end
36
+
37
+ def self.scrape_wta_rankings
38
+ self.scrape("http://www.espn.com/tennis/rankings/_/type/2", "wta")
39
+ end
40
+ end
@@ -0,0 +1,56 @@
1
+ class Player
2
+ attr_accessor :name, :rank, :country, :points, :url, :tour
3
+
4
+ @@all = []
5
+
6
+ def player_bio
7
+ doc = Nokogiri::HTML(open(url))
8
+ metadata = doc.css('.player-bio .player-metadata li')
9
+
10
+ birth_date = metadata[1].text.gsub('Birth Date', '')
11
+ hometown = metadata[2].text.gsub('Hometown', '')
12
+ height = metadata[3] ? metadata[3].text.gsub('Height', '') : "N/A"
13
+ weight = metadata[4] ? metadata[4].text.gsub('Weight', '') : "N/A"
14
+
15
+ puts "=" * 40
16
+ puts "Rank: #{rank}"
17
+ puts "Name: #{name}"
18
+ puts "Birth Date: #{birth_date}"
19
+ puts "Hometown: #{hometown}"
20
+ puts "Country: #{country}"
21
+ puts "Height: #{height}"
22
+ puts "Weight: #{weight}"
23
+ puts "=" * 40
24
+ end
25
+
26
+ def save
27
+ @@all << self
28
+ self
29
+ end
30
+
31
+ def self.all
32
+ @@all.dup.freeze
33
+ end
34
+
35
+ def self.new_from_hash(hash)
36
+ Player.new.tap do |player|
37
+ hash.each { |key, value| player.send("#{key}=", value) }
38
+ end
39
+ end
40
+
41
+ def self.create_from_hash(hash)
42
+ self.new_from_hash(hash).save
43
+ end
44
+
45
+ def self.find_by_name(name)
46
+ @@all.detect { |player| player.name.downcase == name.downcase }
47
+ end
48
+
49
+ def self.find_by_rank_and_tour(rank, tour)
50
+ self.find_by_tour(tour).detect { |player| player.rank == rank }
51
+ end
52
+
53
+ def self.find_by_tour(tour)
54
+ @@all.select { |player| player.tour == tour }
55
+ end
56
+ end
@@ -0,0 +1,15 @@
1
+ class Rankings
2
+ def self.print_rankings(tour)
3
+ Player.find_by_tour(tour).each do |player|
4
+ puts "#{player.rank.ljust(5)}#{player.name.ljust(25)}#{player.country.ljust(25)}#{player.points}"
5
+ end
6
+ end
7
+
8
+ def self.print_atp_rankings
9
+ self.print_rankings('atp')
10
+ end
11
+
12
+ def self.print_wta_rankings
13
+ self.print_rankings('wta')
14
+ end
15
+ end
data/spec.md ADDED
@@ -0,0 +1,6 @@
1
+ # Specifications for the CLI Assessment
2
+
3
+ Specs:
4
+ - [ ] Have a CLI for interfacing with the application
5
+ - [ ] Pull data from an external source
6
+ - [ ] Implement both list and detail views
metadata ADDED
@@ -0,0 +1,132 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: espn-tennis-cli-app
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Sophia Varella
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-02-20 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: '1.7'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: require_all
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.4'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.4'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.13'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.13'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '12.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '12.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.10'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.10'
83
+ description: Gets ATP/WTA Rankings and player bios from the ESPN website
84
+ email:
85
+ - sophiavarella@gmail.com
86
+ executables:
87
+ - espn-tennis
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - ".gitignore"
92
+ - CODE_OF_CONDUCT.md
93
+ - Gemfile
94
+ - Gemfile.lock
95
+ - LICENSE
96
+ - README.md
97
+ - Rakefile
98
+ - bin/console
99
+ - bin/espn-tennis
100
+ - bin/setup
101
+ - config/environment.rb
102
+ - espn-tennis-cli-app.gemspec
103
+ - lib/espn_tennis_controller.rb
104
+ - lib/espn_tennis_scraper.rb
105
+ - lib/player.rb
106
+ - lib/rankings.rb
107
+ - spec.md
108
+ homepage: https://github.com/sophiav/espn-tennis-cli-app
109
+ licenses:
110
+ - MIT
111
+ metadata: {}
112
+ post_install_message:
113
+ rdoc_options: []
114
+ require_paths:
115
+ - lib
116
+ required_ruby_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ required_rubygems_version: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - ">="
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ requirements: []
127
+ rubyforge_project:
128
+ rubygems_version: 2.5.1
129
+ signing_key:
130
+ specification_version: 4
131
+ summary: ESPN Tennis rankings
132
+ test_files: []