fifa_rankings 0.1.0

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: 78bb5a835439a53d2020f83b521376b7eeb95d47
4
+ data.tar.gz: 1a69b9cece494668d481c0854bacacc6d5960e44
5
+ SHA512:
6
+ metadata.gz: 9bac8393f8e8388c7c2cd887bee74babfe648faa6464adb0dd84649f5b92ec5da114642659555b9bb937e5dbf966f43091f6f4471a465baad5841eb57818b5a7
7
+ data.tar.gz: a92afc6f25ca8be79b990df75006e4fa63ed601226382d5a2b8f87fcc362500c0d701259cfbfa661278ddf7f35ed6033612c70fc744407fe8b9a85973269bccc
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/
@@ -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 schun08@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 fifa_rankings.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Sydney Chun
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
+ # FifaRankings
2
+
3
+ Welcome to FifaRankings! This Ruby gem provides a CLI for viewing the current top 20 FIFA Women's Teams as per Wikipedia.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'fifa_rankings'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install fifa_rankings
20
+
21
+ ## Usage
22
+
23
+ Type the below and follow the on screen instructions
24
+
25
+ $ fifa-rankings
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/sydra08/fifa_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.
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,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "fifa_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(__FILE__)
data/bin/fifa-rankings ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require './lib/fifa_rankings/'
5
+
6
+ FifaRankings::CLI.new.call
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
@@ -0,0 +1,37 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'fifa_rankings/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "fifa_rankings"
8
+ spec.version = FifaRankings::VERSION
9
+ spec.authors = ["Sydney Chun"]
10
+ spec.email = ["schun08@gmail.com"]
11
+
12
+ spec.summary = "Lists FIFA World Rankings for the top 20 Women's teams."
13
+ spec.description = "Using data from Wikipedia, lists the top 20 FIFA teams and allows you to learn more information about each team."
14
+ spec.homepage = "https://github.com/sydra08/fifa_rankings"
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 = "bin"
30
+ spec.require_paths = ["lib"]
31
+ spec.executables << "fifa-rankings"
32
+
33
+ spec.add_development_dependency "bundler", "~> 1.14"
34
+ spec.add_development_dependency "rake", "~> 10.0"
35
+ spec.add_development_dependency "pry", "~> 0.10", ">= 0.10.4"
36
+ spec.add_dependency "nokogiri", "~> 1.7", ">= 1.7"
37
+ end
@@ -0,0 +1,90 @@
1
+ class FifaRankings::CLI
2
+
3
+ def call
4
+ welcome
5
+ load_data
6
+ list
7
+ details
8
+ goodbye
9
+ end
10
+
11
+ def welcome
12
+ puts ""
13
+ puts "Welcome!"
14
+ puts "Retrieving FIFA data..."
15
+ end
16
+
17
+ def goodbye
18
+ puts ""
19
+ puts "Goodbye! Come back to see the updated rankings soon."
20
+ end
21
+
22
+ def load_data
23
+ get_teams
24
+ add_attributes
25
+ end
26
+
27
+ def get_teams
28
+ teams = FifaRankings::Scraper.scrape_rankings_page('https://en.wikipedia.org/wiki/FIFA_Women%27s_World_Rankings')
29
+ FifaRankings::Team.create_from_array(teams)
30
+ end
31
+
32
+ def add_attributes
33
+ FifaRankings::Team.all.each do |team|
34
+ # sleep 1.0 + rand
35
+ attributes = FifaRankings::Scraper.scrape_team_page('https://en.wikipedia.org' + team.url)
36
+ team.add_attributes(attributes)
37
+ end
38
+ end
39
+
40
+ def list
41
+ format = '%-6s %-14s %-10s'
42
+
43
+ puts ""
44
+ puts "FIFA Women's World Rankings".upcase
45
+ puts "---------------------------"
46
+ puts ""
47
+ puts format % ["RANK", "TEAM", "CHANGE"]
48
+ FifaRankings::Team.sort_by_rank.each.with_index(1) do |team, i|
49
+ puts format % [i, team.name, team.movement]
50
+ end
51
+ end
52
+
53
+
54
+ def details
55
+ input = nil
56
+ while input != "exit"
57
+ puts ""
58
+ puts ""
59
+ puts "Enter the rank or name of the team that you would like more info on, type 'list' to see whole list, or type 'exit' to leave"
60
+ input = gets.chomp.downcase
61
+
62
+ if input.to_i.between?(1,FifaRankings::Team.all.size) || FifaRankings::Team.find_by_name(input)
63
+ print_team(input)
64
+ elsif input == "list"
65
+ list
66
+ elsif input != "exit"
67
+ puts ""
68
+ puts "Incorrect input, please try again."
69
+ end
70
+
71
+ end
72
+ end
73
+
74
+ def print_team(input)
75
+ team = FifaRankings::Team.find_by_rank(input.to_i) || FifaRankings::Team.find_by_name(input)
76
+
77
+ puts ""
78
+ puts " #{team.name.upcase}"
79
+ puts "-" * 78 #74 is the longest line + 2 on either side for spacing
80
+ puts " Rank:" + " #{team.rank}"
81
+ puts " Points:" + " #{team.points}"
82
+ puts " Confederation:" + " #{team.confederation}"
83
+ puts " Head coach:" + " #{team.head_coach}"
84
+ puts " Team captain(s):" + " #{team.captain}"
85
+ puts " Top scorer(s):" + " #{team.top_scorer}"
86
+ puts " Most caps:" + " #{team.most_caps}"
87
+ puts "-" * 78
88
+ end
89
+
90
+ end
@@ -0,0 +1,56 @@
1
+ class FifaRankings::Scraper
2
+
3
+ def self.scrape_rankings_page(ranking_url)
4
+ doc = Nokogiri::HTML(open(ranking_url))
5
+ teams = []
6
+ i = 2 #this is where the data starts in the table
7
+
8
+ while i < 22 #this is where the data starts in the table
9
+ team = {
10
+ name: doc.css('table.wikitable tr')[i].css('td')[2].css('a').text,
11
+ points: doc.css('table.wikitable tr')[i].css('td')[3].text.to_i,
12
+ url: doc.css('table.wikitable tr')[i].css('td')[2].css('a').attribute('href').value,
13
+ }
14
+ if i < 11 #when it gets to the double digits rank the data changes a bit
15
+ team[:rank] = doc.css('table.wikitable tr')[i].css('td').text.slice(0,1).strip.to_i
16
+ else
17
+ team[:rank] = doc.css('table.wikitable tr')[i].css('td').text.slice(0,2).strip.to_i
18
+ end
19
+ # this converts the Increase/Decrease/Steady into up arrow, down arrow and em dash
20
+ if doc.css('table.wikitable tr')[i].css('td')[1].css('img').attribute('alt').value == "Increase"
21
+ team[:movement] = " \u2206"
22
+ elsif doc.css('table.wikitable tr')[i].css('td')[1].css('img').attribute('alt').value == "Decrease"
23
+ team[:movement] = " \u2207"
24
+ elsif doc.css('table.wikitable tr')[i].css('td')[1].css('img').attribute('alt').value == "Steady"
25
+ team[:movement] = " \u2014"
26
+ end
27
+
28
+ teams << team
29
+ i += 1
30
+ end
31
+
32
+ teams
33
+ end
34
+
35
+ def self.scrape_team_page(team_url)
36
+ doc = Nokogiri::HTML(open(team_url))
37
+ x, i = 0, 0
38
+ attributes = {}
39
+ keys = ["Confederation", "Head coach", "Captain", "Most caps", "Top scorer"]
40
+
41
+ while doc.css('table.infobox tr')[i].css('th').text != "FIFA code"
42
+ if doc.css('table.infobox tr')[i].css('th').text == keys[x]
43
+ if keys[x] == "Confederation"
44
+ attributes[keys[x].downcase.gsub(" ","_").to_sym] = doc.css('table.infobox tr')[i].css('td').text.gsub("\n"," ")
45
+ else
46
+ attributes[keys[x].downcase.gsub(" ","_").to_sym] = doc.css('table.infobox tr')[i].css('td').text.gsub(/\[\d+\]/,"").gsub("\n",", ")
47
+ end
48
+ x += 1
49
+ else
50
+ i += 1
51
+ end
52
+ end
53
+ attributes
54
+ end
55
+
56
+ end
@@ -0,0 +1,42 @@
1
+ class FifaRankings::Team
2
+ attr_accessor :name, :head_coach, :confederation, :rank, :points, :captain, :movement, :most_caps, :top_scorer, :url
3
+
4
+ @@all = []
5
+
6
+ def initialize(team_hash)
7
+ team_hash.each do |k,v|
8
+ self.send(("#{k}="),v)
9
+ end
10
+ @@all << self
11
+ end
12
+
13
+ def self.create_from_array(array)
14
+ # create Team instances from an array of hashes
15
+ array.each {|team| self.new(team)}
16
+ end
17
+
18
+ def add_attributes(attributes_hash)
19
+ # add attributes to Team instances from a hash for the detail view
20
+ attributes_hash.each do |k,v|
21
+ self.send(("#{k}="),v)
22
+ end
23
+ self
24
+ end
25
+
26
+ def self.sort_by_rank
27
+ self.all.sort_by {|team| team.rank}
28
+ end
29
+
30
+ def self.all
31
+ @@all
32
+ end
33
+
34
+ def self.find_by_rank(rank)
35
+ self.all.detect {|team| team.rank == rank}
36
+ end
37
+
38
+ def self.find_by_name(name)
39
+ self.all.detect {|team| team.name.downcase == name.downcase}
40
+ end
41
+
42
+ end
@@ -0,0 +1,3 @@
1
+ module FifaRankings
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,9 @@
1
+ #environment file
2
+ require_relative "fifa_rankings/version"
3
+ require_relative "fifa_rankings/cli"
4
+ require_relative "fifa_rankings/team"
5
+ require_relative "fifa_rankings/scraper"
6
+
7
+ require 'nokogiri'
8
+ require 'pry'
9
+ require 'open-uri'
data/spec.md ADDED
@@ -0,0 +1,9 @@
1
+ # Specifications for the CLI Assessment
2
+
3
+ Specs:
4
+ - [x] Have a CLI for interfacing with the application
5
+ - Have a FifaRankings::CLI class and there is an executable bin/fifa-rankings file that contains the method (FifaRankings::CLI.new.call) to launch the interface
6
+ - [x] Pull data from an external source
7
+ - The app pulls data from Wikipedia's FIFA Women's World Rankings page (https://en.wikipedia.org/wiki/FIFA_Women%27s_World_Rankings) as well as the associated/linked Wikipedia team pages.
8
+ - [x] Implement both list and detail views
9
+ - There is a list view of the top 20 teams sorted by their rank. The list displays the rank, team name, and the change in the team's rank since the last calculation. The detail view, which is accessed when you submit the rank of a particular team, displays the following information about the team (where available): team name, rank, total points, confederation, head coach, team captain(s), top scorer(s), and the player(s) with the most caps.
metadata ADDED
@@ -0,0 +1,130 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fifa_rankings
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Sydney Chun
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-08-10 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.14'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.14'
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.10'
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: 0.10.4
51
+ type: :development
52
+ prerelease: false
53
+ version_requirements: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - "~>"
56
+ - !ruby/object:Gem::Version
57
+ version: '0.10'
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: 0.10.4
61
+ - !ruby/object:Gem::Dependency
62
+ name: nokogiri
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '1.7'
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: '1.7'
71
+ type: :runtime
72
+ prerelease: false
73
+ version_requirements: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - "~>"
76
+ - !ruby/object:Gem::Version
77
+ version: '1.7'
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: '1.7'
81
+ description: Using data from Wikipedia, lists the top 20 FIFA teams and allows you
82
+ to learn more information about each team.
83
+ email:
84
+ - schun08@gmail.com
85
+ executables:
86
+ - fifa-rankings
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - CODE_OF_CONDUCT.md
92
+ - Gemfile
93
+ - LICENSE.txt
94
+ - README.md
95
+ - Rakefile
96
+ - bin/console
97
+ - bin/fifa-rankings
98
+ - bin/setup
99
+ - fifa_rankings.gemspec
100
+ - lib/fifa_rankings.rb
101
+ - lib/fifa_rankings/cli.rb
102
+ - lib/fifa_rankings/scraper.rb
103
+ - lib/fifa_rankings/team.rb
104
+ - lib/fifa_rankings/version.rb
105
+ - spec.md
106
+ homepage: https://github.com/sydra08/fifa_rankings
107
+ licenses:
108
+ - MIT
109
+ metadata: {}
110
+ post_install_message:
111
+ rdoc_options: []
112
+ require_paths:
113
+ - lib
114
+ required_ruby_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ required_rubygems_version: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ requirements: []
125
+ rubyforge_project:
126
+ rubygems_version: 2.6.11
127
+ signing_key:
128
+ specification_version: 4
129
+ summary: Lists FIFA World Rankings for the top 20 Women's teams.
130
+ test_files: []