2019-GCPL-CLI-Table 0.0.0
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 +7 -0
- data/lib/cli.rb +53 -0
- data/lib/scraper.rb +20 -0
- data/lib/team.rb +38 -0
- metadata +46 -0
    
        checksums.yaml
    ADDED
    
    | @@ -0,0 +1,7 @@ | |
| 1 | 
            +
            ---
         | 
| 2 | 
            +
            SHA256:
         | 
| 3 | 
            +
              metadata.gz: 69e9105e1ee85ffbfdd7540a729cf272cbd77e210395aea02fec1c59de7d086f
         | 
| 4 | 
            +
              data.tar.gz: 1720bfc4a02f56990745444c1ea3281685a3f18b3c648f755b1c116512726c33
         | 
| 5 | 
            +
            SHA512:
         | 
| 6 | 
            +
              metadata.gz: 8b4eaa72b72af5c11f88b8075bede628428de5c5720b6e48a3da42b451ae8eedc78258ae8332caa7310ce7a7ad666883e4da9b93f85051c383326bed045e34d8
         | 
| 7 | 
            +
              data.tar.gz: 1077a5020633aa8509bb0cfb5caefcf6fbf0e6b8319ff399e59ed3fa1dab7ceb057718cc8b05b352eca53a6ca641f8b7bd017174cd24bcf0a53ac0333c5e5d3a
         | 
    
        data/lib/cli.rb
    ADDED
    
    | @@ -0,0 +1,53 @@ | |
| 1 | 
            +
            require_relative '../lib/scraper.rb'
         | 
| 2 | 
            +
            require_relative '../lib/team.rb'
         | 
| 3 | 
            +
             | 
| 4 | 
            +
            def table_printer(array)
         | 
| 5 | 
            +
              counter = 0 
         | 
| 6 | 
            +
              array.map do |team|
         | 
| 7 | 
            +
                counter += 1
         | 
| 8 | 
            +
                puts "#{counter}. #{team[0]}"
         | 
| 9 | 
            +
              end
         | 
| 10 | 
            +
              puts "Please select a team(1 - 18):"
         | 
| 11 | 
            +
            end
         | 
| 12 | 
            +
             | 
| 13 | 
            +
            def cli_printer
         | 
| 14 | 
            +
              puts "Welcome to 2019 GCPL table printer!"
         | 
| 15 | 
            +
              puts "Select a team to view:"
         | 
| 16 | 
            +
            end
         | 
| 17 | 
            +
             | 
| 18 | 
            +
            def team_selector
         | 
| 19 | 
            +
              input = gets.strip.to_i
         | 
| 20 | 
            +
              input -= 1
         | 
| 21 | 
            +
              if input <= 18
         | 
| 22 | 
            +
                table = "Team Name: #{Team.all[input].team_name}\t Games Played: #{Team.all[input].games_played}\n Wins:#{Team.all[input].wins}\t Losses: #{Team.all[input].losses}\t Draws: #{Team.all[input].draws}\t Points: #{Team.all[input].points}\n Goals For: #{Team.all[input].goals_for}\t Goals Against: #{Team.all[input].goals_against}"
         | 
| 23 | 
            +
                puts table
         | 
| 24 | 
            +
              else
         | 
| 25 | 
            +
                puts "Please select a valid team"
         | 
| 26 | 
            +
                team_selector
         | 
| 27 | 
            +
              end
         | 
| 28 | 
            +
            end
         | 
| 29 | 
            +
             | 
| 30 | 
            +
            def choose_again
         | 
| 31 | 
            +
              puts "Would you like to see a new team? Y/N"
         | 
| 32 | 
            +
              input = gets.strip
         | 
| 33 | 
            +
              input = input.upcase
         | 
| 34 | 
            +
              if input == "Y"
         | 
| 35 | 
            +
                table_printer(@all_team_data_save)
         | 
| 36 | 
            +
                team_selector
         | 
| 37 | 
            +
                choose_again
         | 
| 38 | 
            +
              elsif input == "N"
         | 
| 39 | 
            +
                puts "Thank you!"
         | 
| 40 | 
            +
              else
         | 
| 41 | 
            +
                puts "Please select Y or N"
         | 
| 42 | 
            +
                choose_again
         | 
| 43 | 
            +
              end
         | 
| 44 | 
            +
            end
         | 
| 45 | 
            +
             | 
| 46 | 
            +
            def print
         | 
| 47 | 
            +
              cli_printer
         | 
| 48 | 
            +
              table_printer(@all_team_data_save)
         | 
| 49 | 
            +
              team_array_build(@all_team_data_save)
         | 
| 50 | 
            +
              team_selector
         | 
| 51 | 
            +
              choose_again
         | 
| 52 | 
            +
            end
         | 
| 53 | 
            +
             | 
    
        data/lib/scraper.rb
    ADDED
    
    | @@ -0,0 +1,20 @@ | |
| 1 | 
            +
            require "open-uri"
         | 
| 2 | 
            +
            require "nokogiri"
         | 
| 3 | 
            +
             | 
| 4 | 
            +
            site = "http://gcplsoccer.bonzidev.com/sam/standings/ss/schedule.php?v=3&divisionID=NDE4MjM5/*"
         | 
| 5 | 
            +
             | 
| 6 | 
            +
            doc = Nokogiri::HTML(open(site))
         | 
| 7 | 
            +
             | 
| 8 | 
            +
            @all_team_data_save = []
         | 
| 9 | 
            +
             | 
| 10 | 
            +
            # Scrapes only team standings from HTML table and shovels into array
         | 
| 11 | 
            +
             | 
| 12 | 
            +
              counter = 1
         | 
| 13 | 
            +
              while counter >=1 && counter <=18
         | 
| 14 | 
            +
                trimmed_table = doc.css("//tr")[counter] #selects rows with teams
         | 
| 15 | 
            +
                counter += 1
         | 
| 16 | 
            +
                textify = trimmed_table.css("td").text.gsub(/(\n|\t|\r)/, " ").gsub(/>\s*</, "><").squeeze(" ") # takes team rows and removes formatting
         | 
| 17 | 
            +
                text = textify.scan(/[a-zA-Z\s][^\d]+|\d+/) #splits data into parts
         | 
| 18 | 
            +
                stats_table = text.join(",").split(",") #transforms into usable array
         | 
| 19 | 
            +
                @all_team_data_save << Array.new(stats_table) #saves data inside an array    
         | 
| 20 | 
            +
              end
         | 
    
        data/lib/team.rb
    ADDED
    
    | @@ -0,0 +1,38 @@ | |
| 1 | 
            +
            require_relative '../lib/scraper.rb'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            class Team
         | 
| 4 | 
            +
              attr_reader :team_name, :games_played, :wins, :losses, :draws, :points, :goals_for, :goals_against
         | 
| 5 | 
            +
              @@all = []
         | 
| 6 | 
            +
             | 
| 7 | 
            +
              def initialize(team_name, games_played, wins, losses, draws, points, goals_for, goals_against)
         | 
| 8 | 
            +
                @team_name = team_name
         | 
| 9 | 
            +
                @games_played = games_played
         | 
| 10 | 
            +
                @wins = wins
         | 
| 11 | 
            +
                @losses = losses
         | 
| 12 | 
            +
                @draws = draws
         | 
| 13 | 
            +
                @points = points
         | 
| 14 | 
            +
                @goals_for = goals_for
         | 
| 15 | 
            +
                @goals_against = goals_against
         | 
| 16 | 
            +
                @@all << self
         | 
| 17 | 
            +
              end
         | 
| 18 | 
            +
             | 
| 19 | 
            +
              def self.all
         | 
| 20 | 
            +
                @@all
         | 
| 21 | 
            +
              end
         | 
| 22 | 
            +
             | 
| 23 | 
            +
             | 
| 24 | 
            +
            end
         | 
| 25 | 
            +
             | 
| 26 | 
            +
            def team_array_build(array)
         | 
| 27 | 
            +
              array.each do |team_data|
         | 
| 28 | 
            +
                team_name = team_data[0].strip
         | 
| 29 | 
            +
                games_played = team_data[1]
         | 
| 30 | 
            +
                wins = team_data[2]
         | 
| 31 | 
            +
                losses = team_data[3]
         | 
| 32 | 
            +
                draws = team_data[4]
         | 
| 33 | 
            +
                points = team_data[5]
         | 
| 34 | 
            +
                goals_for = team_data[6]
         | 
| 35 | 
            +
                goals_against = team_data[7]
         | 
| 36 | 
            +
                Team.new(team_name, games_played, wins, losses, draws, points, goals_for, goals_against)
         | 
| 37 | 
            +
              end
         | 
| 38 | 
            +
            end
         | 
    
        metadata
    ADDED
    
    | @@ -0,0 +1,46 @@ | |
| 1 | 
            +
            --- !ruby/object:Gem::Specification
         | 
| 2 | 
            +
            name: 2019-GCPL-CLI-Table
         | 
| 3 | 
            +
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            +
              version: 0.0.0
         | 
| 5 | 
            +
            platform: ruby
         | 
| 6 | 
            +
            authors:
         | 
| 7 | 
            +
            - Michael Lynch
         | 
| 8 | 
            +
            autorequire: 
         | 
| 9 | 
            +
            bindir: bin
         | 
| 10 | 
            +
            cert_chain: []
         | 
| 11 | 
            +
            date: 2019-10-15 00:00:00.000000000 Z
         | 
| 12 | 
            +
            dependencies: []
         | 
| 13 | 
            +
            description: 
         | 
| 14 | 
            +
            email: michael@michaelrlynch.com
         | 
| 15 | 
            +
            executables: []
         | 
| 16 | 
            +
            extensions: []
         | 
| 17 | 
            +
            extra_rdoc_files: []
         | 
| 18 | 
            +
            files:
         | 
| 19 | 
            +
            - lib/cli.rb
         | 
| 20 | 
            +
            - lib/scraper.rb
         | 
| 21 | 
            +
            - lib/team.rb
         | 
| 22 | 
            +
            homepage: https://rubygems.org/gems.2019-GCPL-CLI-Table
         | 
| 23 | 
            +
            licenses:
         | 
| 24 | 
            +
            - MIT
         | 
| 25 | 
            +
            metadata: {}
         | 
| 26 | 
            +
            post_install_message: 
         | 
| 27 | 
            +
            rdoc_options: []
         | 
| 28 | 
            +
            require_paths:
         | 
| 29 | 
            +
            - lib
         | 
| 30 | 
            +
            required_ruby_version: !ruby/object:Gem::Requirement
         | 
| 31 | 
            +
              requirements:
         | 
| 32 | 
            +
              - - ">="
         | 
| 33 | 
            +
                - !ruby/object:Gem::Version
         | 
| 34 | 
            +
                  version: '0'
         | 
| 35 | 
            +
            required_rubygems_version: !ruby/object:Gem::Requirement
         | 
| 36 | 
            +
              requirements:
         | 
| 37 | 
            +
              - - ">="
         | 
| 38 | 
            +
                - !ruby/object:Gem::Version
         | 
| 39 | 
            +
                  version: '0'
         | 
| 40 | 
            +
            requirements: []
         | 
| 41 | 
            +
            rubyforge_project: 
         | 
| 42 | 
            +
            rubygems_version: 2.7.6
         | 
| 43 | 
            +
            signing_key: 
         | 
| 44 | 
            +
            specification_version: 4
         | 
| 45 | 
            +
            summary: GCPL Season Table printer
         | 
| 46 | 
            +
            test_files: []
         |