Skip to content

ldaniels528/tabular

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

40 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Tabular

A utility class for generating ASCII/text-based tables

Table of Contents

Motivations

There are many instances where I've needed a simple lightweight tool for generating tables for tabular data stored in collections of Scala case classes.

Development

Build Requirements

  • SBT 0.13+

Getting the code

$ git clone git@github.com:ldaniels528/tabular.git

Configuring the project for your IDE

Eclipse project

$ sbt eclipse

Intellij Idea project

$ sbt gen-idea

Building the code

$ sbt clean publish-local

Running the tests

$ sbt test    

Usage Examples

The Scala code:

  @Test
  def basicTable() {
    val groceryList = Seq(
      GroceryItem("Milk", requestedBy = "kids"),
      GroceryItem("Eggs", requestedBy = "Mom"),
      GroceryItem("Cheese", requestedBy = "Mom"),
      GroceryItem("Beer", quantity = 12, requestedBy = "Dad"))

    val tabular = new Tabular()
    tabular.transform(groceryList) foreach logger.info
  }

  case class GroceryItem(item: String, quantity: Int = 1, requestedBy: String)

The output:

2014-08-13 19:44:35 INFO  TabularTest:35 - + ------------------------------- +
2014-08-13 19:44:35 INFO  TabularTest:35 - | item    quantity  requestedBy   |
2014-08-13 19:44:35 INFO  TabularTest:35 - + ------------------------------- +
2014-08-13 19:44:35 INFO  TabularTest:35 - | Milk    1         kids          |
2014-08-13 19:44:35 INFO  TabularTest:35 - | Eggs    1         Mom           |
2014-08-13 19:44:35 INFO  TabularTest:35 - | Cheese  1         Mom           |
2014-08-13 19:44:35 INFO  TabularTest:35 - | Beer    12        Dad           |
2014-08-13 19:44:35 INFO  TabularTest:35 - + ------------------------------- +

About

A simple lightweight utility for creating ASCII/text-based tables

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages