1 Month, 1 Project, A Moment of Reflection, and DON'T FORGET TO TEST YOUR CODE!!!!
Published: 2021-02-26 17:03:58

Since starting this journey at Flatiron, I probably have experienced every emotion imaginable. The feelings of doubt, of not being god enough, and loads and loads of frustration, but my greatest emotion now is pride. I am really proud of getting to this point, and if you are a new FI student reading this I promise it is worth every bit of perseverance that this program requires.

My first project was a CLI application that pulled from an open API called TV Maze. This program pulls one webpage from their show lists randomly and lists 20 shows that would be options. From there the user selects a show to learn more about that particular show. I found a few aspects of building this program out to be challenging that I will detail further. 

The first challenging aspect was building out the CLI logic which took me a while. I based some of it off of how I solved my Tic Tac Toe lab, but the first challenge I had was validating inputs correctly. I realized I could exit the loop by just having my check_input method puts a message when you input exit and not allow it to loop back to the check_input function. 

```def check_input
        input = gets.strip
        puts "-----------------------------------------------------------------------"
        if input.to_i < 21 && input.to_i > 0 && input =~ /^\d+$/
            display_info(input)
            puts "-----------------------------------------------------------------------"
            puts "If you would like to see another show, please put in a number (1-20)".colorize(:yellow)
            puts "-----------------------------------------------------------------------"
            check_input
        elsif input.downcase == "list"
            list_shows
            check_input
        elsif input.downcase == "exit" || input.downcase =="end"
            puts "Thank you for using the New Series Suggester."
            puts "Goodbye!"
            puts "-----------------------------------------------------------------------"
        else
            puts "I'm sorry but that is not a correct input".colorize(:light_red)
            puts "Only numbers 1 - 20, list, exit, or end are valid inputs".colorize(:light_red)
            puts "-----------------------------------------------------------------------"
            check_input
        end
    end ```
 
From there I had error messages being thrown because of Show Objects with a nil value for the Summary attribute. This was being thrown because the gsub methods were trying to work on a nil value which is not allowed. As you can see, an if statement can be used within a line of code to give your program more flexibility. Another type of input validation that had to be worked out was to ensure only integers were accepted as a valid input. I utilized a regex pattern as another condition for my if statement to achieve this. If that Regex was left out, as long as a string start with an integer 1-20 it would accept it.

There is a key lesson in this, test your code! I would have never caught any of these issues above if I did not test my code a thousand times. As of writing this I have not done my review, and I am very grateful that I caught this when I did.

The final topic I wanted to review with my code is the separation of concerns when it comes to objects. As a new student I really urge you to take a step back and think about what you are doing when constructing objects. When I first made my program I added this display method to the show object. After speaking to my cohort lead he got me thinking, should the display method be in the object: Show, after all the CLI is the part of the program we want display the show information. From there I refactored my code to have proper separation of concerns and built this display method into the CLI class.

```def display_info(input)
        newshow = ShowFinder::Show.all[input.to_i - 1]
        puts "Name: #{newshow.name}"
        puts "Genres: #{newshow.genre}"
        puts "Language: #{newshow.language}"
        puts "Network: #{newshow.network}"
        puts "Country: #{newshow.country}"
        puts "Premiered On: #{newshow.premiered}"
        puts "Status: #{newshow.status}"
        puts "Run Time: #{newshow.run_time} minutes"
        puts "Official Website: #{newshow.official_site}"
        puts "Summary: #{newshow.summary.gsub("<p>", "").gsub("</p>", "").gsub("<b>", "").gsub("</b>", "").gsub("<i>", "").gsub("</i>", "")}" if newshow.summary != nil
    end ```
  

Flatiron has been a challenging experience that definitely has its ups and downs, but the sense of pride you will feel when completing projects is unreal. I feel more and more confident by the day about writing code and I really hope my story can inspire even just one other person to try out coding!