mls_standings 0.1.2 → 0.1.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 01b01e6152df9c79ea2f20fd88a49dc18cca88ed
4
- data.tar.gz: 64161b4131d60f33d963bede5bb0cefd7f33437f
3
+ metadata.gz: 67f08ccd16a014c73364cd2f2d9e107261263841
4
+ data.tar.gz: f7351a51b5be4b41252d70f564d9223b93883eb0
5
5
  SHA512:
6
- metadata.gz: 703149aae3f2d65c122445d2ee955cbbd327bff785699d142602cd1fa59093292e3dd242df407930a38c42b35c6c83994e9927c4255a1d7427213705795c65aa
7
- data.tar.gz: 6e461de812eff20a1b642daf0bf0a7ea65a36ba401bf64c8f754875a019aa0101dd3344f0e9ddf816c16d6947d16d1b2b660c30f811bed768d6c434332358c16
6
+ metadata.gz: 209d2788f49bd3247d407f2c3d2323a2100b345b6802a02864ec07b90b7574ba4f1e5024cadd92c8b27a67bc0f07ae720a117d71aac493205b608f067d600802
7
+ data.tar.gz: 3912206f2a72fd9f76378331511d6d90de0d5f13d9681a30ad76b1165aee6d08fbeef18367da38067043a066587078478df2c236fccb697f8d291a2b75c5a1a0
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/
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in mls_standings.gemspec
4
+ gemspec
5
+ gem 'require_all'
data/LICENSE.md ADDED
@@ -0,0 +1,9 @@
1
+ MIT LICENSE
2
+
3
+ Copyright (c) 2018 Alberto Mayanga
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,20 @@
1
+ # MLS Standings
2
+
3
+ This Ruby gem provides a CLI to view the current standings of teams in Major League Soccer during the season.
4
+
5
+ ## Installation
6
+
7
+ You can install this gem via ```gem install mls_standings```. The ```mls_standings``` CLI will be installed and you can run ```mls_standings``` to get a live table to Major League Soccer's current season standings.
8
+
9
+ ## Usage
10
+
11
+ Run: ```mls_standings``` after installing the gem.
12
+ Drill Down to MLS conference standings and team record.
13
+
14
+ ## Contributing
15
+
16
+ Bug reports and pull requests are welcome on GitHub at https://github.com/Booligan/mls-standings-cli-app.
17
+
18
+ ## License
19
+
20
+ The gem is available as open source under the terms of the [MIT](https://github.com/Booligan/mls-standings-cli-app/blob/master/LICENSE.md) License.
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 "mls_standings"
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/mls_standings CHANGED
@@ -1,5 +1,11 @@
1
- #!/usr/bin/env ruby
2
- require "bundler/setup"
3
- require "mls_standings"
4
-
5
- MlsStandings::CLI.new.call
1
+ #!/usr/bin/env ruby
2
+ require "bundler/setup"
3
+ require "mls_standings"
4
+ # require "./lib/mls_standings"
5
+
6
+
7
+ def reload!
8
+ load_all './lib'
9
+ end
10
+
11
+ MlsStandings::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,9 @@
1
+ require 'pry'
2
+ require 'open-uri'
3
+ require 'nokogiri'
4
+ require 'colorize'
5
+
6
+
7
+ require_relative '../lib/mls_standings/scrapper'
8
+ require_relative '../lib/mls_standings/team'
9
+ require_relative '../lib/mls_standings/cli'
@@ -0,0 +1,140 @@
1
+ class MlsStandings::CLI
2
+
3
+ def call
4
+ MlsStandings::Scrapper.create_teams
5
+ start_menu
6
+ end
7
+
8
+ def start_menu
9
+ system "clear"
10
+ puts " ***************".colorize(:blue)
11
+ puts " *MLS Standings*".colorize(:red)
12
+ puts " ***************".colorize(:blue)
13
+
14
+ puts "\n1. Eastern Conference."
15
+ puts "2. Western Conference.\n\n"
16
+ puts "Enter '1' for the MLS Eastern Conference."
17
+ puts "Enter '2' for the MLS Western Conference."
18
+ puts "\nSelect a conference or type 'e' to exit: "
19
+ input = nil
20
+
21
+ until input == 'e' || input == '1' || input == '2'
22
+ input = gets.strip.downcase
23
+ case input.downcase
24
+ when "1"
25
+ eastern_conf
26
+ when "2"
27
+ western_conf
28
+ when "e"
29
+ exit
30
+ else
31
+ puts "Not Valid. Please select a conference: "
32
+ end
33
+ end
34
+ end
35
+
36
+ def eastern_conf
37
+ system "clear"
38
+ puts " MLS Eastern Conference".colorize(:blue)
39
+ puts " **********************".colorize(:blue)
40
+ i = 1
41
+ teams= MlsStandings::Team.eastern_conf
42
+ teams.each do |team|
43
+ puts "#{i}. #{team.name}"
44
+ i += 1
45
+ end
46
+ puts "\nSelect 1-11 to get more information on the team, 's' to switch conference, or exit:"
47
+ input = nil
48
+
49
+ until input == 'et' || input == 's' || input.to_i.between?(1, 11)
50
+ input = gets.strip.downcase
51
+ case
52
+ when input.to_i.between?(1, 11)
53
+ east_team_record(input.to_i)
54
+ when input.downcase == "s"
55
+ western_conf
56
+ when input.downcase == "e"
57
+ exit
58
+ else
59
+ puts "Not a valid team. Please select a valid team or, 's' to switch or 'e' to exit: "
60
+ end
61
+ end
62
+ end
63
+
64
+ def western_conf
65
+ system "clear"
66
+ puts " MLS Western Conference".colorize(:red)
67
+ puts " **********************".colorize(:red)
68
+ i = 1
69
+ teams = MlsStandings::Team.western_conf
70
+ teams.each do |team|
71
+ puts "#{i}. #{team.name}"
72
+ i += 1
73
+ end
74
+ puts "\nSelect 1-11 to get more information on the team, 's' to switch conference, or exit:"
75
+ input = nil
76
+
77
+ until input == 'e' || input == 's'||input.to_i.between?(1, 11)
78
+ input = gets.strip.downcase
79
+ case
80
+ when input.to_i.between?(1, 11)
81
+ west_team_record(input.to_i)
82
+ when input.downcase == "s"
83
+ eastern_conf
84
+ when input.downcase == "e"
85
+ exit
86
+ else
87
+ puts "Not a valid team. Please select a valid team or, 's' or 'e': "
88
+ end
89
+ end
90
+ end
91
+
92
+ def east_team_record(input)
93
+ system "clear"
94
+ team = MlsStandings::Team.eastern_conf[input - 1]
95
+ puts "#{team.name}".colorize(:blue)
96
+ puts "***********************".colorize(:blue)
97
+ puts "Games Played: #{team.games_played}"
98
+ puts "Wins: #{team.wins}"
99
+ puts "Losses: #{team.losses}"
100
+ puts "Ties: #{team.ties}"
101
+ puts "\n Type 'MLS' to restart CLI or 'e' to exit:"
102
+
103
+ until input == 'e' || input == 'mls'
104
+ input = gets.strip.downcase
105
+ case input.downcase
106
+ when "e"
107
+ exit
108
+ when "mls"
109
+ start_menu
110
+ else
111
+ puts "Not Valid. Please select type 'MLS' or 'e': "
112
+ end
113
+ end
114
+ end
115
+
116
+ def west_team_record(input)
117
+ system "clear"
118
+ team = MlsStandings::Team.western_conf[input - 1]
119
+ puts "#{team.name}".colorize(:red)
120
+ puts "***********************".colorize(:red)
121
+ puts "Games Played: #{team.games_played}"
122
+ puts "Wins: #{team.wins}"
123
+ puts "Losses: #{team.losses}"
124
+ puts "Ties: #{team.ties}"
125
+ puts "\n Type 'MLS' to restart CLI or 'e' to exit:"
126
+
127
+ until input == 'e' || input == 'mls'
128
+ input = gets.strip.downcase
129
+ case input.downcase
130
+ when "e"
131
+ exit
132
+ when "mls"
133
+ start_menu
134
+ else
135
+ puts "Not Valid. Please select type 'MLS' or 'exit': "
136
+ end
137
+ end
138
+ end
139
+
140
+ end
@@ -0,0 +1,35 @@
1
+ class MlsStandings::Scrapper
2
+
3
+ def self.get_page
4
+ html = open("https://www.mlssoccer.com/standings")
5
+ Nokogiri::HTML(html)
6
+ end
7
+
8
+ def self.scrape_teams
9
+ html = self.get_page
10
+ table = html.css('.standings_table tbody tr')
11
+ teams_hash_array = []
12
+
13
+ table.each do |team|
14
+ name = team.css('[data-title="Club"] .hide-on-mobile-inline').text
15
+ games_played = team.css('[data-title="Games Played"]').text
16
+ wins = team.css('[data-title="Wins"]').text
17
+ losses = team.css('[data-title="Losses"]').text
18
+ ties = team.css('[data-title="Ties"]').text
19
+ name.slice!('x - ')
20
+ name.slice!('s - ')
21
+ name.slice!('y - ')
22
+ team_hash = {:name => name, :games_played => games_played, :wins => wins, :losses => losses, :ties => ties}
23
+ teams_hash_array << team_hash
24
+ end
25
+ teams_hash_array.delete_at(0)
26
+ teams_hash_array.delete_at(11)
27
+ teams_hash_array
28
+ end
29
+
30
+ def self.create_teams
31
+ teams = self.scrape_teams
32
+ teams.each{|team| MlsStandings::Team.create_from_scrape(team)}
33
+ end
34
+
35
+ end
@@ -0,0 +1,27 @@
1
+ class MlsStandings::Team
2
+ attr_accessor :name, :games_played, :wins, :losses, :ties
3
+
4
+ @@all = []
5
+
6
+ def initialize(team_hash)
7
+ team_hash.each_key{|k| self.send("#{k}=", team_hash[k])}
8
+ @@all << self
9
+ end
10
+
11
+ def self.all
12
+ @@all
13
+ end
14
+
15
+ def self.create_from_scrape(team)
16
+ self.new(team)
17
+ end
18
+
19
+ def self.eastern_conf
20
+ self.all[0..10]
21
+ end
22
+
23
+ def self.western_conf
24
+ self.all[11..22]
25
+ end
26
+
27
+ end
@@ -0,0 +1,3 @@
1
+ module MlsStandings
2
+ VERSION = "0.1.3"
3
+ end
@@ -0,0 +1,9 @@
1
+ require 'open-uri'
2
+ require 'nokogiri'
3
+ require 'colorize'
4
+
5
+ require_relative './mls_standings/version'
6
+ require_relative './mls_standings/team'
7
+ require_relative './mls_standings/cli'
8
+ require_relative './mls_standings/scrapper'
9
+ require_relative '../config/environment'
Binary file
@@ -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 'mls_standings/version'
5
+
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = "mls_standings"
9
+ spec.version = MlsStandings::VERSION
10
+ spec.authors = ["Alberto Mayanga"]
11
+ spec.email = ["aamayanga@gmail.com"]
12
+
13
+ spec.summary = %q{Command line app to view the table standings of Major League Soccer’s current season}
14
+ spec.description = %q{Live table standings coming stright from MLSsoccer.com}
15
+ spec.homepage = "https://github.com/Booligan/mls-standings-cli-app"
16
+ spec.license = "MIT"
17
+
18
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
19
+ f.match(%r{^(test|spec|features)/})
20
+ end
21
+ spec.bindir = "bin"
22
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
23
+ spec.require_paths = ["lib"]
24
+ spec.post_install_message = "What is your favorite team's record? Find out now!"
25
+
26
+
27
+ spec.add_development_dependency "bundler", "~> 1.14"
28
+ spec.add_development_dependency "rake", "~> 10.0"
29
+ spec.add_development_dependency "pry", '~> 0.11.3'
30
+
31
+ spec.add_dependency "nokogiri", '~> 1.8', '>= 1.8.2'
32
+ spec.add_dependency "colorize", '~> 0.8.1'
33
+ end
data/spec.md ADDED
@@ -0,0 +1,14 @@
1
+ # Specifications for the CLI Assessment
2
+
3
+ Specs:
4
+ - [x] Have a CLI for interfacing with the application
5
+ # I built the initial menu for the CLI. It currently displays the title and a menu for which Conference to select, or to exit.
6
+ # Each Conference calls a method to display the teams in the selected conference.
7
+ - [x] Pull data from an external source
8
+ # Used Nokogiri to scrape a table into a variable. I was then able to iterate over each 'tr' tag, and grab the attributes for each team instance.
9
+ # Once all of the data was scraped and pushed into the teams_hash_array, I was able to turn this data into instances of the Team class.
10
+ - [x ] Implement both list and detail views
11
+ # Once all of my instances were created and added to the @@all array, I was able to complete the CLI.
12
+ # The first menu splits Team.all in half to list the league conferences.
13
+ # The second menu shows all of the teams in their respective conferences sorted by their current place on the league table.
14
+ # The third menu shows games played and win-lose-tie record for the selected team.
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mls_standings
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alberto Mayanga
@@ -25,25 +25,19 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.14'
27
27
  - !ruby/object:Gem::Dependency
28
- name: nokogiri
28
+ name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '1.8'
34
- - - ">="
35
- - !ruby/object:Gem::Version
36
- version: 1.8.2
33
+ version: '10.0'
37
34
  type: :development
38
35
  prerelease: false
39
36
  version_requirements: !ruby/object:Gem::Requirement
40
37
  requirements:
41
38
  - - "~>"
42
39
  - !ruby/object:Gem::Version
43
- version: '1.8'
44
- - - ">="
45
- - !ruby/object:Gem::Version
46
- version: 1.8.2
40
+ version: '10.0'
47
41
  - !ruby/object:Gem::Dependency
48
42
  name: pry
49
43
  requirement: !ruby/object:Gem::Requirement
@@ -58,6 +52,26 @@ dependencies:
58
52
  - - "~>"
59
53
  - !ruby/object:Gem::Version
60
54
  version: 0.11.3
55
+ - !ruby/object:Gem::Dependency
56
+ name: nokogiri
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.8'
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: 1.8.2
65
+ type: :runtime
66
+ prerelease: false
67
+ version_requirements: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - "~>"
70
+ - !ruby/object:Gem::Version
71
+ version: '1.8'
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: 1.8.2
61
75
  - !ruby/object:Gem::Dependency
62
76
  name: colorize
63
77
  requirement: !ruby/object:Gem::Requirement
@@ -76,20 +90,37 @@ description: Live table standings coming stright from MLSsoccer.com
76
90
  email:
77
91
  - aamayanga@gmail.com
78
92
  executables:
93
+ - console
79
94
  - mls_standings
95
+ - setup
80
96
  extensions: []
81
97
  extra_rdoc_files: []
82
98
  files:
99
+ - ".gitignore"
100
+ - Gemfile
101
+ - LICENSE.md
102
+ - README.md
103
+ - Rakefile
104
+ - bin/console
83
105
  - bin/mls_standings
106
+ - bin/setup
107
+ - config/environment.rb
108
+ - lib/mls_standings.rb
109
+ - lib/mls_standings/cli.rb
110
+ - lib/mls_standings/scrapper.rb
111
+ - lib/mls_standings/team.rb
112
+ - lib/mls_standings/version.rb
113
+ - mls_standings-0.1.2.gem
114
+ - mls_standings.gemspec
115
+ - spec.md
84
116
  homepage: https://github.com/Booligan/mls-standings-cli-app
85
117
  licenses:
86
118
  - MIT
87
119
  metadata: {}
88
- post_install_message:
120
+ post_install_message: What is your favorite team's record? Find out now!
89
121
  rdoc_options: []
90
122
  require_paths:
91
123
  - lib
92
- - lib/mls_standings
93
124
  required_ruby_version: !ruby/object:Gem::Requirement
94
125
  requirements:
95
126
  - - ">="
@@ -102,7 +133,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
102
133
  version: '0'
103
134
  requirements: []
104
135
  rubyforge_project:
105
- rubygems_version: 2.6.13
136
+ rubygems_version: 2.6.7
106
137
  signing_key:
107
138
  specification_version: 4
108
139
  summary: Command line app to view the table standings of Major League Soccer’s current