Index: /trunk/PS-IPP-Config/lib/PS/IPP/Metadata/Stats.pm
===================================================================
--- /trunk/PS-IPP-Config/lib/PS/IPP/Metadata/Stats.pm	(revision 14113)
+++ /trunk/PS-IPP-Config/lib/PS/IPP/Metadata/Stats.pm	(revision 14114)
@@ -1,5 +1,5 @@
 # Copyright (c) 2006  Paul Price, Joshua Hoblitt
 #
-# $Id: Stats.pm,v 1.21 2007-07-09 21:06:22 eugene Exp $
+# $Id: Stats.pm,v 1.22 2007-07-11 01:18:03 eugene Exp $
 
 package PS::IPP::Metadata::Stats;
@@ -51,4 +51,27 @@
 }
 
+sub cmdflags {
+
+    my $self = shift;                # Where we'll put the information
+
+    # apply the needed calculation to the data based on the type
+    
+    my $cmdflags;
+    my $entries = $self->{entries};
+    
+    foreach my $entry (@$entries) {
+	my $value = $entry->{value};
+	my $flag = $entry->{flag};
+	if ($value =~ m|\S+\s+\S+|) {
+	    # protect values with whitespace 
+	    $cmdflags .= " $flag '$value'";
+	} else {
+	    $cmdflags .= " $flag $value";
+	}
+    }
+
+    return $cmdflags;
+}
+
 # Given a parsed metadata from ppStats, assemble summary statistics
 sub parse {
@@ -68,5 +91,5 @@
 	if ($type eq "constant") {
 	    if (not defined $entry->{value}) {
-		$entry->{value} = 'NAN';
+		$self->_null_for_type ($entry);
 	    }
 	    next;
@@ -80,5 +103,5 @@
 		$entry->{value} = $stats->mean();
 	    } else {
-		$entry->{value} = 'NAN';
+		$self->_null_for_type ($entry);
 	    }
 	    next;
@@ -97,5 +120,5 @@
 		next;
 	    } 
-	    $entry->{value} = 'NAN';
+	    $self->_null_for_type ($entry);
 	    next;
 	}
@@ -109,5 +132,5 @@
 		$entry->{value} = sqrt($stats->mean());
 	    } else {
-		$entry->{value} = 'NAN';
+		$self->_null_for_type ($entry);
 	    }
 	}
@@ -120,5 +143,5 @@
 		$entry->{value} = $stats->sum();
 	    } else {
-		$entry->{value} = 'NAN';
+		$self->_null_for_type ($entry);
 	    }
 	}
@@ -126,4 +149,24 @@
 
     return $self;
+}
+
+sub _null_for_type {
+
+    my ($self, $entry) = @_;
+
+    if ($entry->{dtype} eq "float") {
+	$entry->{value} = 'NAN';
+	return;
+    }
+    if ($entry->{dtype} eq "int") {
+	$entry->{value} = '0';
+	return;
+    }
+    if ($entry->{dtype} eq "string") {
+	$entry->{value} = 'NULL';
+	return;
+    }
+    $entry->{value} = 'NAN';
+    return;
 }
 
@@ -200,4 +243,20 @@
 }
 
+sub value_for_flag {
+
+    my $self = shift;
+    my $flag = shift;
+
+    my $entries = $self->{entries};
+
+    foreach my $entry (@$entries) {
+	if ($flag eq $entry->{flag}) {
+	    return $entry->{value};
+	}
+    }
+    return 'NULL'; # 
+}
+
+
 # Return the data structure for a particular value, or the entire hash
 sub data {
