Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sonota88/mrtable
Mrtable implementation for Ruby
https://github.com/sonota88/mrtable
ruby
Last synced: about 24 hours ago
JSON representation
Mrtable implementation for Ruby
- Host: GitHub
- URL: https://github.com/sonota88/mrtable
- Owner: sonota88
- License: mit
- Created: 2017-10-12T14:41:41.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2019-04-14T22:32:36.000Z (over 5 years ago)
- Last Synced: 2024-12-01T16:07:45.498Z (25 days ago)
- Topics: ruby
- Language: Ruby
- Homepage:
- Size: 20.5 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# Mrtable
Machine readable table.
## Installation
Add this line to your application's Gemfile:
```ruby
gem 'mrtable'
```And then execute:
$ bundle
Or install it yourself as:
$ gem install mrtable
## Example
```ruby
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 | | |
EOBheader, 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](http://opensource.org/licenses/MIT).