/soccer-challenge

A Ruby script that reads a txt file of game results for a soccer league and prints the top teams at the end of each match day to the terminal.

Primary LanguageRubyMIT LicenseMIT

Soccer Challenge

By Danielle Thompson 1/2023

Description

This simple problem is a script that reads a listing of game results for a soccer league and prints the top teams at the end of each match day.

The rules

In this league, a draw (tie) is worth 1 point and a win is worth 3 points. A loss is worth 0 points. If two or more teams among the top three teams have the same number of points, they should have the same rank and be printed in alphabetical order. That said, at most three teams should be listed in the output per matchday.

To Do

  1. Open the txt file, read the file line by line, & save the data.
  2. Recognize the start and end of a matchday w/script.
  3. Output top 3 point-scoring matchday winners by matchday.
  4. Output should be sorted by points first, highest to lowest, then by alphabetical order in case any team have equal points.

Input: txt file with results of games, one per line # of teams / 2 = number of games played on each matchday

Output:

Matchday 1
San Jose Earthquakes, 3 pts
Santa Cruz Slugs, 3 pts
Felton Lumberjacks, 2 pts

...

User Stories

# Stories
1 A user should be able to tell when a matchday begins and ends.
2 A user should be able to see the results of the top 3 point-scoring teams per matchday.

Technology Used

  • VS Code
  • Ruby v3.2.0
  • rspec v3.12
  • git v2.37.2 & GitHub

Instructions

Getting Started

Running the Project Locally

This project requires that you have Ruby, git, and a code editor of your choosing installed in your local system. If that is not the case, the directions in "details" can help get you started.

For Mac Users

  • Open a new Terminal window.
  • If you don't already have it, install the package manager, Homebrew, on your device by entering this line of code: $ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)".
  • Once homebrew is installed, install Git, a version control system for code writers, with this line of code: brew install git.
  • Install ruby-install, a tool for installing Ruby with $ brew install ruby-install.
  • Install the latest version (as of 1/10/23) Ruby with $ ruby-install ruby 3.2.0.

For Windows Users

  • Open a new Command Prompt window by typing "Cmd" in your computer's search bar.
  • Determine whether you have 32-bit or 64-bit Windows by following these instructions.
  • Go to Git Bash, click on the "Download" button, and download the corresponding exe file from the Git for Windows site.
  • Follow the instructions in the set up menu.
  • There is no one direct way to get Ruby set up on a Windows computer. I would recommend following a guide like this one, which will have more expertise than I can personally provide at this time.

Cloning the Project

  • Click the green 'Code' button in this repository to "Download Zip" & open the unzipped folder in your code editor of choice. Alternately, in your CLI after navigating to your desktop folder with the command cd Desktop, use the GitHub CLI command gh repo clone danitcodes/soccer-challenge.
  • (Optional: If you would like to save your own copy of the repository to your GitHub account, click the "Fork" button in the upper right hand corner of the main repository page.)
  • Navigate to the folder 'soccer-capstone' from your CLI with the command cd soccer-capstone.
  • Open the project in the code editing application of your choice, like VS Code, by running the command code . or by R-clicking and opening.

Setup

  • Upon opening the project in a code editor, make sure to bundle required gems with bundle.

Tests

  • To run the test suit, run rspec in the root directory of the project from the terminal.

Make It Go

  • To run the script itself, type ruby lib/game_results.rb.

Additional Notes

The sample-input.txt file has been included as an example input text file for this script to run with. If a file other than the example provided is needed to provide game inputs, that .txt file will simply need to be added to the root "soccer-challenge" folder, and the appropriate base file name will need to be substituted in the static_filename variable of the lib/game_results.rb file.


Stretch Goals // Known Bugs // Suggested Features

Report bugs & request features here.

  • No bugs known at this time.
  • With more time, I would include more tests. Being out of TDD practice and time, I heavily utilized REPL-driven development. However, I have left comments of some of the unit testing ideas I might explore in the test file.
  • I would also follow a stricter Red, Green, Refactor workflow for unit tests. Not using unit testing much currently, this is a place I have room for improvement.
  • There is some code repetition and crossed lines in the logic that I would continue digging into refactor, DRY up, separate out concerns, and generally just smooth out.
  • A feature that could be useful in the future if points are accumulative between matchdays is to output total points in all matches played by team.

Legal/License

This software is licensed under the GitHub.
Copyright (c) 2023 Danielle Thompson