toString method
A string representation of this object.
Some classes have a default textual representation,
often paired with a static parse
function (like int.parse).
These classes will provide the textual representation as
their string representation.
Other classes have no meaningful textual representation
that a program will care about.
Such classes will typically override toString
to provide
useful information when inspecting the object,
mainly for debugging or logging.
Implementation
@override
String toString() {
final columns = [...numericColumns.keys, ...categoricColumns.keys],
table = toListOfMaps(),
maxWidths = {
for (final key in columns)
key: [
key.length,
...[for (final row in table) row[key]!.length]
].reduce(math.max)
},
line = (String edge, String connect) =>
edge +
[for (final column in columns) "-" * maxWidths[column]!]
.join(connect) +
edge,
row = (Iterable<String> cells) => "|${cells.join("|")}|",
sb = StringBuffer("\n")
..writeln(line(".", "."))
..writeln(row(columns.map((key) => key.padRight(maxWidths[key]!))))
..writeln(line(":", "+"));
for (final r in table) {
sb.writeln(row(columns.map(
(key) => r[key]!.replaceAll('"', "").padRight(maxWidths[key]!))));
}
sb.writeln(line("'", "'"));
return sb.toString();
}