Skip to content

sonota88/mrtable

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

36 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Mrtable

Machine readable table.

Installation

Add this line to your application's Gemfile:

gem 'mrtable'

And then execute:

$ bundle

Or install it yourself as:

$ gem install mrtable

Example

require 'pp'
require 'mrtable'

mrtable_text = <<'EOB'
| c1  | c2  | c3  | c4  |
| --- | --- | --- | --- |
| "123" | "abc" | "日本語" |    |
|  123  |  abc  |  日本語  |    |
| "" | " " | "  " |  |
| "\\\t\r\n\"" |  |  |  |
|  \\\t\r\n\"  |  |  |  |
| "a" | " a" | "a " | " a " |
|  a  |   a  |  a   |   a   |
| "\|" | "1 \| 2" |  |  |
|  \|  |  1 \| 2  |  |  |
| "null" | "NULL" |  |  |
|  null  |  NULL  |  |  |
EOB

header, rows = Mrtable.parse(mrtable_text)
pp header, rows

=begin

["c1", "c2", "c3", "c4"]
[["123", "abc", "日本語", nil],
 ["123", "abc", "日本語", nil],
 ["", " ", "  ", nil],
 ["\\\t\r\n" + "\"", nil, nil, nil],
 ["\\\t\r\n" + "\"", nil, nil, nil],
 ["a", " a", "a ", " a "],
 ["a", "a", "a", "a"],
 ["|", "1 | 2", nil, nil],
 ["|", "1 | 2", nil, nil],
 ["null", "NULL", nil, nil],
 ["null", "NULL", nil, nil]]

=end

puts Mrtable.generate(header, rows)

=begin

| c1         | c2     | c3     | c4    |
| ---------- | ------ | ------ | ----- |
|        123 | abc    | 日本語 |       |
|        123 | abc    | 日本語 |       |
| ""         | " "    | "  "   |       |
| \\\t\r\n\" |        |        |       |
| \\\t\r\n\" |        |        |       |
| a          | " a"   | "a "   | " a " |
| a          | a      | a      | a     |
| \|         | 1 \| 2 |        |       |
| \|         | 1 \| 2 |        |       |
| null       | NULL   |        |       |
| null       | NULL   |        |       |

=end

License

The gem is available as open source under the terms of the MIT License.

About

Mrtable implementation for Ruby

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages