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|
end
Reading from am IO object
atv = ATV.new(io)
atv.each do |row|
end
More examples can be found in the Examples of Testing With ASCII Tables repo.
Contributing
- Fork it ( https://github.com/kellyfelkins/atv )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request