Outputting JSON From Ruby
Last night I got the scraper to write an output.txt file which listed all the contents of words_by_selector
. Today I want to make it write to JSON instead of plain text and I want to back it with some tests.
Last night I got the scraper to write an output.txt file which listed all the contents of words_by_selector
. Today I want to make it write to JSON instead of plain text and I want to back it with some tests.
I just spent a few hours talking to my friend Derek(@derekebradley) about Ruby and it occured to me that I never finished this scraper project. We got awfully far with it but then it kind of died on the vine. Thankfully, I wrote it all down. down. down.
The fact of the matter is I didn’t know where to take the data. I didn’t have a design or a layout that I could put it all into. I want to change all that. I want to turn this into something useful. But first I have to make sense of all the code that was written so many weeks ago.
Alright, contuing from yesterday we want to take our little Node module and make it available to the world as a really awesome command line tool.
This post is going to be short and sweet because I have to help my lady pack for her big trip to Germany. Over the past few days I’ve been messing around with command line tools written in Ruby so today I decided to give it a shot in Node.
So yesterday we saw how to setup and run ruby scripts as executables from the command line. While this is pretty rad, it definitely has its limitations. For one, it’s not very portable and secondly it just isn’t very flexible or powerful. If we stuck with this approach we’d need to write our own semantic versioning, we’d have to setup a way to make sure that all of our required 3rd party gems get installed properly… really it’ll just be a big mess if we try to hand-roll it.
Instead we’re going to turn to Bundler to help us manage our files and turn our command line tool into a ruby gem. I’m going to start fresh and create a totally new tool, called zerp
. I don’t know what zerp
’s purpose will be in the long run, but today we’re going to make it print some text to verify everything is working.
Yesterday I tried to do a post on creating your first Ruby Gem as a command line tool. It didn’t go very well. In an effort to better understand what goes on with command line tools I’m going to start from the most basic, a ruby script that is in our PATH
.