My name is Germila SAINT-JEAN

I am studying at Flatiron school

I just come to build my first Ruby gem that provides a Command Line Interface (CLI) to an external data source
My project’s name is “daily-deal”

A little description of my project:
This is a walk through on setting up a small command line interface to keep show a list of products with the name, the price and the availability.

CLIs are a great tool to have when working in an application where you want a simple, stable interface that provides low level API’s to your application’s data.

I want to show you how create this Ruby Gem
In my case i work on VSCode
1. Setting up a gem to do this is really straight forward with bundler. They have some nice docs on this.
Follow this guide “https://guides.rubygems.org/” If you are new to Ruby and do not know anything about gems, I highly recommend reading some of the material on Ruby Gems.


Using Bundler to set up your Ruby Gem:
Once you have followed the setup instructions in the project’s README, set up the skeleton of the ruby gem by running bundle gem daily_deal
This generates a directory named daily_deal with a Rakefile, and a daily_deal.gemspec also various other supporting files.

Before we can do anything else, we need to ensure our gemspec file is valid. The generated version has some TODOs setup. We will go ahead and update the file replacing those TODOs with the information for daily_deal (as below).

Once the file has the required information, we can run bundle install to be sure we have all the dependencies we need to get going!


For adding simple functionality to the Gem

We are going to add code to lib/daily_deal.rb

For adding more complex functionality to the gem
We create a new file called cli to lib/daily_deal
The goal is to be able
Have list deals
Have menu
and goodbye
We create 4 methods: Call, list_deals, menu, goodbye

We create a new file to /lib/daily_deal called deal
This file will have the list of the recent products to the “https://meh.com" and “https://woot.com"

We create a file called daily-deal in the bin directory. In this file we will create a new instance of the class DailyDeal and call the initial instruction method

It is the file that we must build on our terminal like this: ./bin/daily-deal
We add a new functionality to the bin by chmod +X daily_deal for running without using ruby when we build the app.

I use in my project a new gem that call “nocogiri” that’s the reason i added it to daily-deal.gemspec and the new version
Like this: “spec.add_dependency “nokogiri”, “~> 1.8.5”

We must require the the directory “./lib/daily_deal” to /bin/daily_deal
Require the gem nocogiri and open_uri

Require_relative all files to /lib/daily_deal (version.rb, deal.rb, cli.rb) in the /lib/daily_deal/dealy_deal.rb

Require the gem nocogiri and open_uri
Require_relative all files to /lib/daily_deal (version.rb, deal.rb, cli.rb) in the /lib/daily_deal/dealy_deal.rb.

Here the link that you can find my gem on Ruby Gem

Ruby Gem : https://rubygems.org/gems/daily_deal
Github: https://github.com/germilasaintjean/daily_deal.git

Youtube: https://www.youtube.com/results?search_query=germila+saint+jean

I hope you liked the post!

Haiti @Software Engineer #Student at Ecole Superieure d’Infotronique d’Haiti(ESIH) #Programmer at NouKod #https://www.linkedin.com/in/germila-saint-jean-763b541