# Summary.pm
#
# Copyright (c) 2002 Cunningham & Cunningham, Inc.
# Released under the terms of the GNU General Public License version 2 or later.
#
# Perl translation by Dave W. Smith <dws@postcognitive.com>

package Summary;

use base qw(Fixture);
use strict;

my $countsKey = "counts";

sub doTable {
    my $self = shift;
    my($table) = @_;
    $Fixture::summary{$countsKey} = $self->counts()->toString();

    my @keys = sort keys %Fixture::summary;
    $table->parts()->more($self->rows(@keys));
}

sub rows {
    my $self = shift;
    my(@keys) = @_;

    return undef if 0 == @keys;
    my $key = shift @keys;

    my $result = Tr(Td($key, Td($Fixture::summary{$key}, undef)),
                    $self->rows(@keys));
    $self->mark($result) if $key eq $countsKey;
    return $result;
}

sub Tr {
    my($parts, $more) = @_;
    return Parse->from("tr", undef, $parts, $more);
}

sub Td {
    my($body, $more) = @_;
    return Parse->from("td", $body, undef, $more);
    
}

sub mark {
    my $self = shift;
    my($cell) = @_;

    my $official = $self->counts();
    $self->counts(new Counts());
    if ( $official->{'wrong'} + $official->{'exceptions'} > 0 ) {
	$self->wrong($cell);
    } else {
	$self->right($cell);
    }

    $self->counts($official);
}

1;
