Day 37: Working on my App and Finishing Exercise 39 at Learn Ruby the Hard Way

I had a day off from work so spent a good portion of the day enjoying being off work. I am back now to finish the long lesson last night from Learn Ruby the Hard Way: Exercise 39: Hashes, Oh Lovely Hashes.

So, the second portion of the Exercise had a module, dict.rb, and then another file full of hashes to run using the module. Here is the code:

and the test file:

demosthenes131@rails-tutorial:~/workspace/LRTHW (master) $ ruby ex39_test.rb
———-
NY State has: New York
OR State has: Portland
———-
Michigan’s abbreviation is: MI
Florida’s abbreviation is: #Dict.get(states, ‘Florida’)}
———-
Michigan has: Detroit
Florida has: Jacksonville
———-
Michigan
MI
New York
NY
Florida
FL
Oregon
OR
California
CA
———-
CA
San Francisco
OR
Portland
NY
New York
MI
Detroit
FL
Jacksonville
———-
Sorry, no Texas.
The city for the state ‘TX’ is: Does not exist

And now back to my app!

I added a way to preserve added data today via YAML

Here is the BookTracker main file:

the Book class file:

and what happens when I add information:

First session:

demosthenes131@book_tracker:~/workspace (master) $ ruby book_tracker.rb
Select an option from the below choices
a: Add a Book
p: View the Books
s: Search the Books
e: Exit
a
Book title: Storm Front
Author: Jim Butcher
Genre: Urban Fantasy
Have you read it, listened to it, or is it a wish list item? Listened
Write a short, one sentence, review! Amazing
Select an option from the below choices
a: Add a Book
p: View the Books
s: Search the Books
e: Exit
e
[#]

At this point I was having a lot of trouble originally. Everytime I restarted the app and entered a new book the previous book was deleted. I fixed this by adding the open() to the run method which would then populate the array. Next session after this (also after I removed a few items that I will re-add later):

demosthenes131@book_tracker:~/workspace (master) $ ruby book_tracker.rb
Select an option from the below choices
a: Add a Book
e: Exit
a
Book title: Hounded
Author: Kevin Hearne
Genre: Urban Fantasy
Have you read it, listened to it, or is it a wish list item? Read it
Write a short, one sentence, review! Fun
Select an option from the below choices
a: Add a Book
e: Exit
e
[#, #]

And here is the YAML output file:

My plan tomorrow is to work on the search and print functions!