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.
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.
- Open the txt file, read the file line by line, & save the data.
- Recognize the start and end of a matchday w/script.
- Output top 3 point-scoring matchday winners by matchday.
- 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
...
# | 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. |
- VS Code
- Ruby v3.2.0
- rspec v3.12
- git v2.37.2 & GitHub
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.
- 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
.
- 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.
- 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 commandgh 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.
- Upon opening the project in a code editor, make sure to bundle required gems with
bundle
.
- To run the test suit, run
rspec
in the root directory of the project from the terminal.
- To run the script itself, type
ruby lib/game_results.rb
.
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.
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.