crystal_fmt

produces text tables from a grid of strings

Build Status

Crystal Format (crystal_fmt)

Takes a grid of strings and produces a text table with custom borders, dividers, and header separator.

For example:

[["things", "stuff"],["a", "b"], ["c", nil]]

would be converted to...

| things | stuff |
| ------ | ----- |
| a      | b     |
| c      |       |

Inspired by the fmt egg for Chicken Scheme.

Installation

Add this to your application's shard.yml:

dependencies:
  crystal_fmt:
    github: masukomi/crystal_fmt

Usage

API Documentations is available here.

require "crystal_fmt"

# SIMPLE USAGE
table_data = Array(Array(String | Nil)).new
[["column 1", "column 2"], ["a", "b"], ["c", "d"]].each do |row|
  table_data << row
end

t = Table.new(table_data)
t.format
# ^^^ produces
# | column 1 | column 2 |
# | -------- | -------- |
# | a        | b        |
# | c        | d        |

# CUSTOM DIVIDERS AND BORDERS
options = Hash(Symbol,String|Bool).new
options[:left_border] = "> "
options[:right_border] = " <"
options[:divider] = " . "
options[:header_divider] = "^"
t.format(options)
# Produces
# > column 1 . column 2 <
# > ^^^^^^^^ . ^^^^^^^^ <
# > a        . b        <
# > c        . d        <

Development

Before developing any feature please create an issue where you describe your idea.

Before working on a bug, please make sure there isn't already a GitHub Issue for it. If there is, make sure no-one's already working on it. If there isn't please create one.

If you have a useful sounding idea I'll probably want to merge it. If you've already coded up improvements for yourself, go ahead and file an Issue describing it and then make a PR.

Note: while I really want to add your contributions, no PR will be merged without passing unit tests.

Please ping me at @masukomi on Twitter so that I see your Issue promptly.

Contributing

  1. Fork it ( https://github.com/masukomi/crystal_fmt/fork )
  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
  6. Poke @masukomi on Twitter to make sure it gets seen promptly.

Contributors

  • masukomi masukomi - creator, maintainer
Repository

crystal_fmt

Owner
Statistic
  • 2
  • 1
  • 0
  • 2
  • 0
  • almost 6 years ago
  • December 1, 2017
License

MIT License

Links
Synced at

Fri, 22 Nov 2024 04:19:46 GMT

Languages