unpack numeric values separated by commas
authorDobrica Pavlinusic <dpavlin@rot13.org>
Wed, 26 May 2010 16:57:29 +0000 (18:57 +0200)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Wed, 26 May 2010 16:57:29 +0000 (18:57 +0200)
This is first multi-value quirk for text file format, based on
"Plants For a Future" data set: species.txt has numeric comma seprated values
so we just unroll them to get nice facets

README
lib/MojoFacets/Data.pm

diff --git a/README b/README
index 3745ca1..a6d72ca 100644 (file)
--- a/README
+++ b/README
@@ -8,6 +8,7 @@ Put JSON file from Simile Exhibit project in data/ with extension .js or .json
 Alternative format is pipe (|) separated text files with extension .txt
 First column is always header with field names
 Multi-line values should be wrapped in ^multi-line-text^
+Multiple values for one field are supported for: number, number
 
 
 Start with:
index dee9765..e69c16e 100644 (file)
@@ -95,7 +95,12 @@ sub _load_path {
                                }
                        }
                        my $item;
-                       $item->{ $header[$_] || "f_$_" } = [ $v[$_] ] foreach ( 0 .. $#v );
+                       foreach my $i ( 0 .. $#v ) {
+                               my $v = $v[$i];
+                               # unpack numeric values separated by commas
+                               my $a = $v =~ m/\d+\s*,\s*\d+/ ? [ split(/\,\s*/,$v) ] : [ $v ];
+                               $item->{ $header[$i] || "f_$i" } = $a;
+                       }
                        push @{ $data->{items} }, $item;
                }
        } else {