summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xdobble.pl59
1 files changed, 29 insertions, 30 deletions
diff --git a/dobble.pl b/dobble.pl
index 84db265..76583cb 100755
--- a/dobble.pl
+++ b/dobble.pl
@@ -96,8 +96,8 @@ package CardsTable {
}
}
- sub html_table($self,$lines) {
- my @ret = ('<table>');
+ sub _build_table($self,$lines,$row_coderef) {
+ my @ret = ();
# this thing is isomorphic to its dual! we don't need to pivot
# lines/points, it's all the same
@@ -110,39 +110,38 @@ package CardsTable {
my $column = $symbol->[1];
$row[$column] = $symbol->[0];
}
- push @ret,' <tr>';
- for my $s (@row) {
- next unless $s or $self->padding;
- push @ret, ' <td>',$s||'&nbsp;','</td>';
- }
- push @ret, ' </tr>';
+ push @ret, $row_coderef->(
+ $self->padding
+ ? @row
+ : grep { $_ } @row
+ );
}
- push @ret,'</table>';
return \@ret;
}
- sub text_table($self,$lines) {
- my @ret = ();
-
- # this thing is isomorphic to its dual! we don't need to pivot
- # lines/points, it's all the same
-
- for my $line (sort keys $lines->%*) {
- my @row;
- for my $point ($lines->{$line}->@*) {
+ sub html_table($self,$lines) {
+ my $ret = $self->_build_table(
+ $lines,
+ sub {
+ return (
+ ' <tr>',
+ ( map {; ' <td>', ($_ || '&nbsp;'), ' </td>' } @_ ),
+ ' </tr>',
+ );
+ },
+ );
+ unshift $ret->@*,'<table>';
+ push $ret->@*,'</table>';
+ return $ret;
+ }
- my $symbol = $self->symbol_for($point);
- my $column = $symbol->[1];
- $row[$column] = $symbol->[0];
- }
- my $string = '';;
- for my $s (@row) {
- next unless $s or $self->padding;
- $string .= $s||' ';
- }
- push @ret, $string;
- }
- return \@ret;
+ sub text_table($self,$lines) {
+ return $self->_build_table(
+ $lines,
+ sub {
+ join '',map { $_ || ' ' } @_;
+ },
+ );
}
};