Mini APPS

Website Overview Book Viewer

Expense Tracker

This is a command-line application. To use it, you'll need to download the files.

Expense Tracker

How it Works

A Hashbang directs the program to the bash interpreter. An instance method of a CLI class accepts command line arguments from the user, stores them in the ARGV array, and initializes an instance of an ExpenseData class. The ExpenseData instance establishes a SQL database connection via the PG RubyGem, and sets up a table with the required schema. The user's arguments trigger database queries which are sanitized to prevent malicious injections. A private method extracts data from the resulting tuple object and displays the expenses.

Highlights

  • When the program is run without arguments, a list of potential commands is shown to the suer.
  • The user can enter a string to search for expenses.
  • If the user wants to clear all records, confirmation is required. The IO class and STDIN#getch allow for the confirmation to be gathered in a single keystroke.

Challenges

  • Visually formatting expense data for display was difficult due to the varying lengths of all table column names and the values involved. String#rjust and Kernel#sprintf were a big help.
  • Working with tuple objects is confusing. Even though they are hash-like objects, ruby methods cannot be called on them.

Source Code: GitHub


Website Overview Book Viewer