From 2c8d9972340cb72f8eb5c0eb1385eb32ae657144 Mon Sep 17 00:00:00 2001 From: Dobrica Pavlinusic Date: Wed, 26 May 2010 18:57:29 +0200 Subject: [PATCH] unpack numeric values separated by commas 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 | 1 + lib/MojoFacets/Data.pm | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/README b/README index 3745ca1..a6d72ca 100644 --- 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: diff --git a/lib/MojoFacets/Data.pm b/lib/MojoFacets/Data.pm index dee9765..e69c16e 100644 --- a/lib/MojoFacets/Data.pm +++ b/lib/MojoFacets/Data.pm @@ -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 { -- 2.20.1