Project

to_ascii

0.0
No commit activity in last 3 years
No release in over 3 years
Adds the #to_ascii method to a number of collection type classes to print out a nicely formatted ASCII table of the attributes of each element.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.5
>= 0
~> 3.1.0

Runtime

 Project Readme

ToAscii

Adds the #to_ascii method to a number of collection type classes to print out a nicely formatted ASCII table of the attributes of each element.

Installation

Add this line to your application's Gemfile:

gem 'to_ascii'

And then execute:

$ bundle

Or install it yourself as:

$ gem install to_ascii

Usage

Require an adapter. By default the to_ascii method doesn't get added to anything until you require one of the following:

require 'to_ascii/adapters/active_record'
require 'to_ascii/adapters/enumerable'
require 'to_ascii/adapters/array'
require 'to_ascii/adapters/all' # requires all of the above

Then:

Person.where(:last_name => 'Newton').to_ascii do
  column :id, 6 # number is the column width
  column :first_name, 24
  column :last_name, 32
end

You can also define visitor/serializer classes based on model names:

class PersonToAscii < ToAscii::Visitor
  column :id, 6
  column :first_name, 24
  column :last_name, 32
end

And then Person.where(:last_name => 'Newton').to_ascii just works. Look, ma! No block!

Or, create visitor classes that are called whatever and pass them into #to_ascii yourself!

class GarblyNamed < ToAscii::Visitor
  column :id, 6
  column :first_name, 24
  column :last_name, 32
end

Person.where(:last_name => 'Newton').to_ascii(GarblyNamed)

Contributing

  1. Fork it ( http://github.com/thejayvm/to_ascii/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request