Read data from ascii tables
Switch branches/tags
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
lib
test
.gitignore
Gemfile
LICENSE.txt
README.md
Rakefile
atv.gemspec

README.md

ATV: Ascii Table Values

ATV is a reader for data in ascii table format. It allows you to read data formatted like this:

|------------------+--------------------|
| name             | dob                |
|------------------+--------------------|
| Malcolm Reynolds | September 20, 2468 |
|------------------+--------------------|
| Zoe Washburne    | February 15, 2484  |
|------------------+--------------------|

or, without separators, like this:

|------------------+--------------------|
| name             | dob                |
|------------------+--------------------|
| Malcolm Reynolds | September 20, 2468 |
| Zoe Washburne    | February 15, 2484  |
|------------------+--------------------|

In Ascii Tables For Clearer Testing I discuss using ascii tables to improve comprehension of software tests.

This gem was originally created when I worked at Indiegogo. Indiegogo has graciously transferred ownership of the gem to me so that I can maintain it going forward.

Installation

Add this line to your application's Gemfile:

gem 'atv'

And then execute:

$ bundle

Or install it yourself as:

$ gem install atv

Usage

Rows are returned or yielded as CSV::Row objects.

|-----------------------+------------------------------+-----------------------------------|
| **Ascii Table Value** | **Returned Value**           | **Notes**                         |
|-----------------------+------------------------------+-----------------------------------|
| Malcolm Reynolds      | "Malcolm Reynolds"           | Most values returned as string    |
|-----------------------+------------------------------+-----------------------------------|
| 123                   | "123"                        | including numbers                 |
|-----------------------+------------------------------+-----------------------------------|
| wrapped strings are   | "wrapped strings are folded" | Similar to yaml, wrapped          |
| folded                |                              | strings are folded with a single  |
|                       |                              | space replacing the new line      |
|-----------------------+------------------------------+-----------------------------------|
|                       | nil                          | The CSV::Row object will have nil |
|                       |                              | for blank values                  |
|-----------------------+------------------------------+-----------------------------------|
| null                  | nil                          | null, true, and false are         |
|                       |                              | special values                    |
|-----------------------+------------------------------+-----------------------------------|
| true                  | true                         |                                   |
|-----------------------+------------------------------+-----------------------------------|
| false                 | false                        |                                   |
|-----------------------+------------------------------+-----------------------------------|
#| commented rows        | not included                 | As you would expect, commented    |
#|                       |                              | rows are not included             |
#|-----------------------+------------------------------+-----------------------------------|

Reading a String

atv = ATV.from_string(string)
atv.each do |row|
  # use row here...
end

Reading from am IO object

atv = ATV.new(io)
atv.each do |row|
  # use row here...
end

More examples can be found in the Examples of Testing With ASCII Tables repo.

Contributing

  1. Fork it ( https://github.com/kellyfelkins/atv )
  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 a new Pull Request