I'm a web developer with base at Buenos Aires, Argetina, and this is a little place to publish a little bit about what I'm wasting most of my time during the week. Don't expect nothing particularly good.

Since last time I worked with color_routes gem I had one one issue in the todo list: separating the table generator used for that job, so it could be used I any other program.

So here's the the tablizer the gem, and says hello to you:

    table = [
        ['animal',              'familia',      'cantidad de patas',    'pelaje'                ],
        ['ornitorrinco',        'mamiferos',    '4',                    'mediano y marron'      , "something"],
        ['pato',                'aves',         '2',                    'plumas blancas'        ],
        ['gato',                'mamiferos',    '4',                    'gris y corto'          ],
        ['marmota',             'mamiferos',    '4',                    'color natural y corto' ]

    mytable = Table.new(table, header: true, align: 'rjust')
    puts mytable

    =>  +------------+---------+-----------------+---------------------+---------+
        |   Animal   | Familia |Cantidad de patas|       Pelaje        |         |
        |ornitorrinco|mamiferos|                4|     mediano y marron|something|
        |        pato|     aves|                2|       plumas blancas|         |
        |        gato|mamiferos|                4|         gris y corto|         |
        |     marmota|mamiferos|                4|color natural y corto|         |

The table object has the [] and []= methods, that lets you access it's data and manipulate it. Adiotionally, has ANSI codes support, so do things like this:

    mytable[0,3]    # => 'gato'
    mytable[0,6]    # => nil
    mytable[3,2] = 'something in red'.color(:red)

The object accepts options in hash form, like:

  • header: true/false
  • footer: true/false
  • align: ansi_ljust/ansi_rjust/ansicenter