DEV Community

madelinemc
madelinemc

Posted on

Adding a little pretty to my first CLI project

Just like that it’s time for my first project - it’s only been 3 weeks but apparently I can code a CLI program! I almost didn’t believe it at first, especially when the scraping proved to be extremely touchy, but once I found the right website and a light-hearted concept I could play around with for several days, it actually happened. For their phase one project, Flatiron requires gathering information in two scrapes and creating instances of classes and relationships between them. I chose a flower delivery service that sends “bundles” of flowers for people to DIY their own bouquet. A happy little thought for 2020 :)

I used my first scrape to collect the name, price and url of all of the “bundles” of flowers, instantiating instances of my Bouquet class in the process. I present the bundle names to the user indexed and ask for input on which one the user would like to learn more about. The user input initiates the second scrape which adds the description and a list of items included in the bundle to the selected Bouquet class and the displays it. The user can choose to select that instance or return to view all of the instances. Creating the relationships clicked for me but the tricky part was getting all of the methods to work together from class to class and making sure I was writing them in the class that made the most sense. For example, I had my first scrape and the method to print it inside my scraper class instead of within the class that held all of the individual “bundle” instances.

But once I got through the hard part of making sure my methods are all within the correct class and then refactoring so that they are the simplest they could be, I got to start the fun part - adding some prettiness to the otherwise boring terminal output.

You can go a long way in terms of presentation just by adding some \n enters to group certain parts of the program together but I wanted to take it a step further. ASCII art was too large and pixellated for the look I wanted for my little flower shop, but after lots of poking around, I discovered Unicode! Aka cute little symbols. There were lots of flowers - I was totally sold but it doesn’t come with instructions… As far as I could tell, no one else on the internet wants to use flowers to make a logo for a simple command line project.

They are presented as unicode: U+0273F which I discovered Ruby does not like! She does like when you use the literals for unicode along with the quotes and curly brackets, a la: \u{0273F} .
Woohoo, a flower!

Enter fullscreen mode Exit fullscreen mode

Equipped with all my little flowers, I named my CLI project Bloom Shop and went about swapping the o’s for flowers. My first go was setting them equal to variables within my run method and placing the variables directly into a string.

    bloom_one = "\u{0273F}"
    bloom_two = "\u{02740}"
    bloom_three = "\u{0273B}"
    puts "bl#{bloom_one}#{bloom_two}m sh#{bloom_three}p"
Enter fullscreen mode Exit fullscreen mode

But that seemed bulky and the string wasn’t readable when someone scanned over the code. I needed to figure out how to create the variable outside of the method but utilize it inside…insert class variables to save the day! I could call it within a string as well as simply puts it on its own.

@@logo = "bl\u{0273F}\u{02740}m sh\u{0273B}p"
Enter fullscreen mode Exit fullscreen mode
        puts @@logo
        puts "this is the logo #{@@logo} of the shop"
Enter fullscreen mode Exit fullscreen mode

Next up, just a little color. I wanted a lot of choices for adding a little color and the Ruby Rainbow gem does just that. A simple way to use is wrapping your string with Rainbow(“string").colorname or as I did in my project, you can choose an RGB color and note it as Rainbow(“string”).color(0, 0, 0)

    @@logo = Rainbow("bloom shop").mediumspringgreen
    @@logo = Rainbow("bl\u{0273F}\u{02740}m sh\u{0273B}p").color(135,215,95)
Enter fullscreen mode Exit fullscreen mode

Ta-da! Ain’t she (as)purdy(as she could be)?! If only there were a way to make it larger...

Screen Shot 2020-10-25 at 6.50.29 PM

See the code at: https://github.com/madelinemc/cli-floral-scraper
And check out lots of other unicode symbols like my flowers: https://www.toptal.com/designers/htmlarrows/symbols/
Ruby Rainbow gem: https://github.com/sickill/rainbow
Also, where I did some digging on the \u syntax: https://docs.ruby-lang.org/en/2.4.0/syntax/literals_rdoc.html

Top comments (0)