Angelo Urtula
6 min readMar 21, 2021

--

Scraping with Ruby to Make a CLI App for Quick League of Legends ARAM Builds

Nautilus, a champion from League of Legends

When playing a mode like ARAM (All Random, All Mid) in League of Legends that gives you a randomly chosen champion to play, you’ll find yourself playing a lot of champions that you may not be familiar with. Most people play it for some casual fun with friends, but it’s also a good way to get out of your comfort zone consisting of your favorite champions. By doing so, you’ll be forced to learn new champions and hopefully add them to your pool of champions that you can play proficiently. When it comes to learning new champions, aside from the champion’s mechanics and gameplay, the initial aspect of a champion that you’ll need to learn is their “build”. You’ll need to know what runes you’ll need to choose, what summoner spells to use, and how to properly allocate your skill points in order to make sure that you’re starting off on the right foot. What’s more, when choosing your runes and summoner spells for that champion, you’ll only be able to make those changes during the “Champion Select” screen, which has a countdown timer before all changes are locked in and you’re thrown into the match. That being said, if you don’t know a champ’s build, you’d need to look it up quick in order to make the correct rune and summoner spell choices! With that in mind, I decided to make an easy-to-use CLI app that scrapes data from https://u.gg/ , which is a site that provides recommended builds for champions based on match statistics, including win rate and pick rate for each portion of the build.

When making my CLI app, dubbed “ARAM_Quick_Build”, I separated the working parts into three different classes. The first class was the Scraper, which scrapes the data from u.gg. The second class was Champ, which handles the data from the scraper, making objects out of the data from Scraper. The third and final class was the CommandLineInterface, which handles all of the user interaction and input from the user, while displaying information about the objects created in the Champ class.

Scraper class

Starting with the Scraper class, I needed to make sure to require both “open-uri” and “nokogiri”. Passing the url https://u.gg/lol/champions through open-uri and nokogiri allows me to access the HTML from u.gg and parse the data from the HTML. Using CSS selectors on that HTML data, I can then pinpoint more finely the data that I need in order to make my objects in the Champ class later on. In the first class method “get_those_champs”, I’m scraping the name of each champion and their URL that directs you to their corresponding build. The second class method “champ_build” takes in the champ_url scraped from the previous class method as an argument in order to access the HTML data from the build page specific to the champion chosen by the user.

Champ class

In the Champ class, I’m taking all of the data scraped from the Scrape class in order to create objects representing each champion. Their attributes include their name, their build URL(which was used in the second Scraper class method to access data for their specific build), and aspects of their build, including runes, summoner spells, and skill priority. The first method to address here is the class method “from_list_of_champs”, which takes the data scraped by the first Scrape class method “get_those_champs” and makes an object out of each champion by running each champion through the initialize method. With each champion being its own object, the “give_build_method” adds each aspect of their build to their object by assigning them new attributes from the data scraped by the second Scraper class method “champ_build”. Aside from that, the “what_is_build?” will be used in the CLI class in order to display the champ’s build. There is also a Champ class method “all” that just returns all of the champ objects, which will be used more in the CLI class.

CLI class

The CLI class takes everything from the Champ class and displays the information to the user as the user uses number inputs to select the champion they want to view. The instance method “run” sets the order in which the other methods will run when a new instance of the CommandLineInterface is called in the “run.rb” file. Initially, it will greet the user. Next, using the “make_list” method, it creates champion objects by calling on both the Scraper class method “get_those_champs” and the Champ class method “from_list_of_champs”. To recap, the aforementioned Scraper class method will scrape the names and urls for each champion, and the Champ class method takes that data to create champion objects using that data as their initial attributes. Afterward, the CLI lists all of the champs in alphabetic order each with an index using the “list_champs” method. The “options” method is where most of the magic happens, as it takes the user input of a number 1 through 154 to display the build for the champion chosen by the user. The “options” method uses a while loop that keeps the CLI running as long as the user does not type in exit. As an aside, I had to choose whether I would have each champion initialize with their build information at the start of the CLI instance, similar to the “make_list” instance method, so all of their build information would be loaded and assigned to each champion object before the CLI started asking for user input. However, when I tried that, the process would take too long to run because it would have to go through all 154 champions and scrape their build information individually. It made more sense to have the app Scrape the build info for only whichever champion the user was interested in. Thus, in the “options” method, when the user gives a valid number 1–154, the Scraper class method “champ_build” and the Champ class method “all” are called to scrape the build information for the chosen champion and give the champion object its build attributes. Once the user is done and types “exit”, the final method in CommandLineInterface “wish_you_luck” runs, which wishes the user good luck before exiting out of the CLI app.

Overall, it was challenging to figure out how one class will speak to another. However, mapping out how to do so with a flow chart made the process much easier. Once I figured that out, the biggest challenge was figuring out the correct CSS selectors to use in the Scraper class to get the data I was interested in. I realized that some of it takes some guess work and trial and error to get the right working selector. The first two for champion name and url were straightforward enough, but I definitely had to look up how to access the alt values of img classes for the second Scraper class method.

At the start of this project, I felt lost on how to even start! It was the first time I would be making something from scratch and I wouldn’t be able to check if I was doing something right by just typing the good old “learn test”. Having gone through the whole process though, I can safely say I have a much better understanding of how to make my own apps. Seeing my CLI app working, despite how simple it may be, gives me confidence because from that I can see that I AM making progress as a software developer.

--

--