Skip to content

Instantly share code, notes, and snippets.

@redthor
Forked from pthiers/PHP-Array.groovy
Last active February 10, 2020 21:52
Show Gist options
  • Select an option

  • Save redthor/a4f20da4c0483fb294bcdeb763a7302f to your computer and use it in GitHub Desktop.

Select an option

Save redthor/a4f20da4c0483fb294bcdeb763a7302f to your computer and use it in GitHub Desktop.

Revisions

  1. redthor revised this gist Feb 10, 2020. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions PHP-Array.groovy
    Original file line number Diff line number Diff line change
    @@ -18,17 +18,17 @@ NEWLINE = System.getProperty("line.separator")
    count = 0;

    def printRow = { values, valueToString ->
    OUT.append("[")
    OUT.append("[\n")
    values.eachWithIndex { value, idx ->
    def str = valueToString(value)
    OUT.append("'").append(value.name()).append("' => ")
    if(str == "NULL") {
    OUT.append(" '").append(value.name()).append("' => ")
    if(str == "NULL" || str.isNumber()) {
    OUT.append(str).append(",")
    } else {
    OUT.append("'").append(str).append("',")
    }
    OUT.append(NEWLINE)
    }
    OUT.append("],")
    OUT.append("],\n")
    }
    ROWS.each { row -> printRow(COLUMNS, { FORMATTER.format(row, it) }) }
  2. @pthiers pthiers created this gist May 11, 2017.
    34 changes: 34 additions & 0 deletions PHP-Array.groovy
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,34 @@
    /*
    * Available context bindings:
    * COLUMNS List<DataColumn>
    * ROWS Iterable<DataRow>
    * OUT { append() }
    * FORMATTER { format(row, col); formatValue(Object, col) }
    * TRANSPOSED Boolean
    * plus ALL_COLUMNS, TABLE, DIALECT
    *
    * where:
    * DataRow { rowNumber(); first(); last(); data(): List<Object>; value(column): Object }
    * DataColumn { columnNumber(), name() }
    */

    SEPARATOR = ","
    QUOTE = "\'"
    NEWLINE = System.getProperty("line.separator")
    count = 0;

    def printRow = { values, valueToString ->
    OUT.append("[")
    values.eachWithIndex { value, idx ->
    def str = valueToString(value)
    OUT.append("'").append(value.name()).append("' => ")
    if(str == "NULL") {
    OUT.append(str).append(",")
    } else {
    OUT.append("'").append(str).append("',")
    }
    OUT.append(NEWLINE)
    }
    OUT.append("],")
    }
    ROWS.each { row -> printRow(COLUMNS, { FORMATTER.format(row, it) }) }