table_print

the best data slicer!

TL;DR This 3 minute screencast will show you what it's all about! (prefer reading? scroll down)

Installation # Install as a standalone gem $ gem install table_print # Install within rails In your Gemfile: gem "table_print" $ bundle install

Exploration The heart of table_print is - you guessed it - a table! It's an efficient way to view a list of structured data, making it easy to scan and compare across large swaths of records (and for many people, it's a comfortable return to the SQL command line output of yesteryear :) TablePrint tries to use sensible defaults to choose the columns to show. If you're inspecting ActiveRecord objects, it uses the ActiveRecord column names. If you're not using ActiveRecord, the table_print default is to show all the methods that are defined directly on your object (nothing from superclasses/mixins). > tp Book.all AUTHOR | SUMMARY | TITLE ----------------------------------------------------------------------- Michael Connelly | Another book by Michael Con... | The Fifth Witness Manning Mardale | From acclaimed historian Ma... | Malcolm X Tina Fey | Worth it. -Trees | Bossypants You can customize the output to show fewer columns, or show other methods you've written on your model. Use symbols or strings to reference the columns. > tp Book.all, :author, "title" AUTHOR | TITLE ------------------------------------- Michael Connelly | The Fifth Witness Manning Mardale | Malcolm X Tina Fey | Bossypants

Contextualization The most powerful feature of table_print is the ability to see your data in the context of other objects it relates to. You can reference nested objects with the method chain required to reach them. This example is showing data from three different tables: name from the Author table (reached through author.name )

table (reached through ) title from the Book table (reached through author.books.title )

table (reached through ) caption from the Photo table (reached through author.books.photos.caption ) > tp Author.limit(3), "name", "books.title", "books.photos.caption" NAME | BOOKS.TITLE | BOOKS.PHOTOS.CAPTION ------------------------------------------------------------------------- Michael Connelly | The Fifth Witness | Susan was running, fast, away... | | Along came a spider. | Malcolm X | | Bossypants | Yes! Yes! A thousand times ye... | | Don't see many like you aroun... Carrot Top | | Milton Greene | How I Learned | Once upon a time, I was a sma... | | Lemons are yellow, limes are ... | | Never as a woman her age. I l... | Desperados | Avast. | | Giraffes lived a peaceful exi...

Configuration Tired of typing the same thing over and over? I gotchu. You can create your own set of defaults on a per-class basis. tp.set Book, :id, :title # now when you print books, only id and title will be shown > tp Book.all ID | TITLE ----------------------- 1 | The Fifth Witness 2 | Malcolm X 3 | Bossypants # you can override your own defaults just like the built-in defaults > tp Book.all, :author AUTHOR ----------------- Michael Connelly Manning Mardale Tina Fey # you can also use include/except to modify the default > tp Book.all, :include => [:author] ID | AUTHOR | TITLE ------------------------------------------ 1 | Michael Connelly | The Fifth Witness 2 | Manning Mardale | Malcolm X 3 | Tina Fey | Bossypants # back to square one - print all the columns we can find > tp.clear Book

Communication I'm happy to help you work through whatever problems you have, take suggestions for features, or just shoot the breeze. I'm @archslide on twitter and @arches on github. Get in touch!

Further Reading This is just an overview of table_print capabilities. Visit the github README for more in-depth explanation of features and options.