Permalink
Browse files

Adding custom separators option

  • Loading branch information...
1 parent cd4f313 commit 0818218988210d5c7b99108c5bdf297ed830a43b Elomar + Rafael committed Mar 14, 2010
View
@@ -53,6 +53,7 @@ gets turned into this JSON:
Usage: csv2json [INPUT] [OPTIONS]
Specific options:
+ -s, --separator SEP Set separator character surrounded by single quotes (default is ',')
-o, --output FILE Write output to a file
-h, --help Show this message
-v, --version Show version
@@ -102,4 +103,4 @@ or in-memory
Copyright (c) 2009 Antonin Hildebrand. See LICENSE for details.
-Check out [http://binaryage.com](http://binaryage.com)
+Check out [http://binaryage.com](http://binaryage.com)
View
@@ -13,12 +13,17 @@ module CSV2JSONRunner
options = OpenStruct.new
options.output = "-"
+ options.separator = ","
opts = OptionParser.new do |o|
o.banner = USAGE
o.separator ""
o.separator "Specific options:"
+ o.on("-s", "--separator SEP", "Set separator character surrounded by single quotes (default is ',')") do |sep|
+ options.separator = sep
+ end
+
o.on("-o", "--output FILE", "Write output to a file") do |fn|
options.output = fn
end
@@ -54,8 +59,8 @@ module CSV2JSONRunner
end
# run the command
- CSV2JSON.parse(IN, OUT)
+ CSV2JSON.parse(IN, OUT, nil, :col_sep => options.separator)
# leave in peace
OUT.flush
-end
+end
View
@@ -11,10 +11,10 @@ def convert(val)
end
# input and output are file objects, you can use StringIO if you want to work in memory
- def parse(input, output, headers=nil)
+ def parse(input, output, headers=nil, options={})
result = Array.new
- FasterCSV.new(input).each do |row|
+ FasterCSV.new(input, options).each do |row|
# treat first row as headers if the caller didn't provide them
unless headers
headers = row
@@ -33,4 +33,4 @@ def parse(input, output, headers=nil)
module_function :parse
module_function :convert
-end
+end
File renamed without changes.
@@ -0,0 +1,16 @@
+Office|Address1|Address2|Address3|City|State|Zip|Phone|Fax
+Headquarters|1600 Amphitheatre Parkway|||Mountain View|CA|94043|650-253-0000|650-253-0001
+New York Sales & Engineering Office|76 Ninth Avenue|||New York|NY|10011|212-565-0000|212-565-0001
+Ann Arbor Sales Office|201 South Division Street|||Ann Arbor|MI|48104|734-332-6500|734-332-6501
+Atlanta Sales & Engineering Office|10 10th Street NE|||Atlanta|GA|30309|404-487-9000|404-487-9001
+Boulder Sales & Engineering Office|2590 Pearl St.|||Boulder|CO|80302|303-245-0086|303-535-5592
+Cambridge Sales & Engineering Office|5 Cambridge Center|||Cambridge|MA|02142|617-682-3635|617-249-0199
+Chicago Sales & Engineering Office|20 West Kinzie St.|||Chicago|IL|60610|312-840-4100|312-840-4101
+Coppell Sales Office|701 Canyon Drive|||Coppell|TX|75019|214-451-4000|214-451-4001
+Detroit Sales Office|114 Willits Street|||Birmingham|MI|48009|248-351-6220|248-351-6227
+Irvine Sales & Engineering Office|19540 Jamboree Road|||Irvine|CA|92612|949-794-1600|949-794-1601
+Pittsburgh Engineering Office|4720 Forbes Avenue|||Pittsburgh|PA|15213||
+Santa Monica Sales & Engineering Office|604 Arizona Avenue|||Santa Monica|CA|90401|310-460-4000|310-309-6840
+Seattle Engineering Office|720 4th Avenue|||Kirkland|WA|98033|425-739-5600|425-739-5601
+Seattle Sales Office|501 N. 34th Street|||Seattle|WA|98103|206-876-1500|206-876-1501
+Washington D.C. Public Policy Office|1001 Pennsylvania Avenue NW|||Washington|DC|20004|202-742-6520|
@@ -0,0 +1,16 @@
+Office;Address1;Address2;Address3;City;State;Zip;Phone;Fax
+Headquarters;1600 Amphitheatre Parkway;;;Mountain View;CA;94043;650-253-0000;650-253-0001
+New York Sales & Engineering Office;76 Ninth Avenue;;;New York;NY;10011;212-565-0000;212-565-0001
+Ann Arbor Sales Office;201 South Division Street;;;Ann Arbor;MI;48104;734-332-6500;734-332-6501
+Atlanta Sales & Engineering Office;10 10th Street NE;;;Atlanta;GA;30309;404-487-9000;404-487-9001
+Boulder Sales & Engineering Office;2590 Pearl St.;;;Boulder;CO;80302;303-245-0086;303-535-5592
+Cambridge Sales & Engineering Office;5 Cambridge Center;;;Cambridge;MA;02142;617-682-3635;617-249-0199
+Chicago Sales & Engineering Office;20 West Kinzie St.;;;Chicago;IL;60610;312-840-4100;312-840-4101
+Coppell Sales Office;701 Canyon Drive;;;Coppell;TX;75019;214-451-4000;214-451-4001
+Detroit Sales Office;114 Willits Street;;;Birmingham;MI;48009;248-351-6220;248-351-6227
+Irvine Sales & Engineering Office;19540 Jamboree Road;;;Irvine;CA;92612;949-794-1600;949-794-1601
+Pittsburgh Engineering Office;4720 Forbes Avenue;;;Pittsburgh;PA;15213;;
+Santa Monica Sales & Engineering Office;604 Arizona Avenue;;;Santa Monica;CA;90401;310-460-4000;310-309-6840
+Seattle Engineering Office;720 4th Avenue;;;Kirkland;WA;98033;425-739-5600;425-739-5601
+Seattle Sales Office;501 N. 34th Street;;;Seattle;WA;98103;206-876-1500;206-876-1501
+Washington D.C. Public Policy Office;1001 Pennsylvania Avenue NW;;;Washington;DC;20004;202-742-6520;
File renamed without changes.
@@ -0,0 +1,13 @@
+thumbpath|imgpath|imgsrc|width|height|thumbsrc|thumbwidth|thumbheight
+thumbnails/|images/|paris_01.jpg|350|262|paris_01.jpg|75|56
+thumbnails/|images/|paris_02.jpg|262|350|paris_02.jpg|75|56
+thumbnails/|images/|paris_03.jpg|350|262|paris_03.jpg|75|56
+thumbnails/|images/|paris_04.jpg|262|350|paris_04.jpg|56|75
+thumbnails/|images/|paris_05.jpg|262|350|paris_05.jpg|56|75
+thumbnails/|images/|paris_06.jpg|350|262|paris_06.jpg|75|56
+thumbnails/|images/|paris_07.jpg|262|350|paris_07.jpg|56|75
+thumbnails/|images/|paris_08.jpg|262|350|paris_08.jpg|56|75
+thumbnails/|images/|paris_09.jpg|262|350|paris_09.jpg|56|75
+thumbnails/|images/|paris_10.jpg|350|262|paris_10.jpg|75|56
+thumbnails/|images/|paris_11.jpg|350|262|paris_11.jpg|75|56
+thumbnails/|images/|paris_12.jpg|350|262|paris_12.jpg|75|56
@@ -0,0 +1,13 @@
+thumbpath;imgpath;imgsrc;width;height;thumbsrc;thumbwidth;thumbheight
+thumbnails/;images/;paris_01.jpg;350;262;paris_01.jpg;75;56
+thumbnails/;images/;paris_02.jpg;262;350;paris_02.jpg;75;56
+thumbnails/;images/;paris_03.jpg;350;262;paris_03.jpg;75;56
+thumbnails/;images/;paris_04.jpg;262;350;paris_04.jpg;56;75
+thumbnails/;images/;paris_05.jpg;262;350;paris_05.jpg;56;75
+thumbnails/;images/;paris_06.jpg;350;262;paris_06.jpg;75;56
+thumbnails/;images/;paris_07.jpg;262;350;paris_07.jpg;56;75
+thumbnails/;images/;paris_08.jpg;262;350;paris_08.jpg;56;75
+thumbnails/;images/;paris_09.jpg;262;350;paris_09.jpg;56;75
+thumbnails/;images/;paris_10.jpg;350;262;paris_10.jpg;75;56
+thumbnails/;images/;paris_11.jpg;350;262;paris_11.jpg;75;56
+thumbnails/;images/;paris_12.jpg;350;262;paris_12.jpg;75;56
File renamed without changes.
@@ -0,0 +1,54 @@
+Geographic area|Total population|Under 18 years|18 to 24 years|25 to 44 years|45 to 64 years|65 years and over|Median age (years)|All ages|18 years and over|Flag|Website
+United States| 281421906| 25.7| 9.6| 30.2| 22.0| 12.4| 35.3| 96.3| 93.4|flag_unitedstates.gif| http://www.usa.gov/
+Alabama| 4447100| 25.3| 9.9| 29.0| 22.8| 13.0| 35.8| 93.3| 89.6|flag_alabama.gif| http://www.alabama.gov/
+Alaska| 626932| 30.4| 9.1| 32.5| 22.3| 5.7| 32.4| 107.0| 107.6|flag_alaska.gif|http://www.alaska.gov/
+Arizona| 5130632| 26.6| 10.0| 29.5| 20.9| 13.0| 34.2| 99.7| 97.7|flag_arizona.gif|http://www.arizona.gov/
+Arkansas| 2673400| 25.4| 9.8| 28.1| 22.7| 14.0| 36.0| 95.3| 92.1|flag_arkansas.gif|http://www.arkansas.gov/
+California| 33871648| 27.3| 9.9| 31.6| 20.5| 10.6| 33.3| 99.3| 97.1|flag_california.gif|http://www.california.gov/
+Colorado| 4301261| 25.6| 10.0| 32.6| 22.2| 9.7| 34.3| 101.4| 100.0|flag_colorado.gif|http://www.colorado.gov/
+Connecticut| 3405565| 24.7| 8.0| 30.3| 23.2| 13.8| 37.4| 93.9| 90.5|flag_connecticut.gif|http://www.connecticut.gov/
+Delaware| 783600| 24.8| 9.6| 30.2| 22.4| 13.0| 36.0| 94.4| 91.0|flag_delaware.gif|http://www.delaware.gov/
+District of Columbia| 572059| 20.1| 12.7| 33.1| 21.9| 12.2| 34.6| 89.0| 86.1||http://www.districtofcolumbia.gov/
+Florida| 15982378| 22.8| 8.3| 28.6| 22.7| 17.6| 38.7| 95.3| 92.5|flag_florida.gif|http://www.florida.gov/
+Georgia| 8186453| 26.5| 10.2| 32.4| 21.3| 9.6| 33.4| 96.8| 94.0|flag_georgia.gif|http://www.georgia.gov/
+Hawaii| 1211537| 24.4| 9.5| 29.9| 22.9| 13.3| 36.2| 101.0| 99.4|flag_hawaii.gif|http://www.hawaii.gov/
+Idaho| 1293953| 28.5| 10.7| 28.0| 21.5| 11.3| 33.2| 100.5| 98.5|flag_idaho.gif|http://www.idaho.gov/
+Illinois| 12419293| 26.1| 9.8| 30.6| 21.5| 12.1| 34.7| 95.9| 92.9|flag_illinois.gif|http://www.illinois.gov/
+Indiana| 6080485| 25.9| 10.1| 29.5| 22.1| 12.4| 35.2| 96.3| 93.3|flag_indiana.gif|http://www.indiana.gov/
+Iowa| 2926324| 25.1| 10.2| 27.6| 22.2| 14.9| 36.6| 96.3| 93.4|flag_iowa.gif|http://www.iowa.gov/
+Kansas| 2688418| 26.5| 10.3| 28.6| 21.4| 13.3| 35.2| 97.7| 95.0|flag_kansas.gif|http://www.kansas.gov/
+Kentucky| 4041769| 24.6| 9.9| 30.0| 23.0| 12.5| 35.9| 95.6| 92.5|flag_kentucky.gif|http://www.kentucky.gov/
+Louisiana| 4468976| 27.3| 10.6| 28.9| 21.6| 11.6| 34.0| 93.8| 90.1|flag_louisiana.gif|http://www.louisiana.gov/
+Maine| 1274923| 23.6| 8.1| 29.1| 24.8| 14.4| 38.6| 94.8| 91.7|flag_maine.gif|http://www.maine.gov/
+Maryland| 5296486| 25.6| 8.5| 31.4| 23.1| 11.3| 36.0| 93.4| 89.8|flag_maryland.gif|http://www.maryland.gov/
+Massachusetts| 6349097| 23.6| 9.1| 31.3| 22.4| 13.5| 36.5| 93.0| 89.5|flag_massachusetts.gif|http://www.massachusetts.gov/
+Michigan| 9938444| 26.1| 9.4| 29.8| 22.4| 12.3| 35.5| 96.2| 93.2|flag_michigan.gif|http://www.michigan.gov/
+Minnesota| 4919479| 26.2| 9.6| 30.4| 21.8| 12.1| 35.4| 98.1| 95.6|flag_minnesota.gif|http://www.minnesota.gov/
+Mississippi| 2844658| 27.3| 10.9| 28.4| 21.4| 12.1| 33.8| 93.4| 89.6|flag_mississippi.gif|http://www.mississippi.gov/
+Missouri| 5595211| 25.5| 9.6| 29.1| 22.3| 13.5| 36.1| 94.6| 91.3|flag_missouri.gif|http://www.missouri.gov/
+Montana| 902195| 25.5| 9.5| 27.2| 24.4| 13.4| 37.5| 99.3| 97.2|flag_montana.gif|http://www.montana.gov/
+Nebraska| 1711263| 26.3| 10.2| 28.5| 21.5| 13.6| 35.3| 97.2| 94.6|flag_nebraska.gif|http://www.nebraska.gov/
+Nevada| 1998257| 25.6| 9.0| 31.5| 23.0| 11.0| 35.0| 103.9| 103.2|flag_nevada.gif|http://www.nevada.gov/
+New Hampshire| 1235786| 25.0| 8.4| 30.9| 23.8| 12.0| 37.1| 96.8| 94.1|flag_newhampshire.gif|http://www.newhampshire.gov/
+New Jersey| 8414350| 24.8| 8.0| 31.2| 22.7| 13.2| 36.7| 94.3| 90.9|flag_newjersey.gif|http://www.newjersey.gov/
+New Mexico| 1819046| 28.0| 9.8| 28.4| 22.2| 11.7| 34.6| 96.7| 94.0|flag_newmexico.gif|http://www.newmexico.gov/
+New York| 18976457| 24.7| 9.3| 30.7| 22.3| 12.9| 35.9| 93.1| 89.4|flag_newyork.gif|http://www.newyork.gov/
+North Carolina| 8049313| 24.4| 10.0| 31.1| 22.5| 12.0| 35.3| 96.0| 93.3|flag_northcarolina.gif|http://www.northcarolina.gov/
+North Dakota| 642200| 25.0| 11.4| 27.2| 21.6| 14.7| 36.2| 99.6| 97.8|flag_northdakota.gif|http://www.northdakota.gov/
+Ohio| 11353140| 25.4| 9.3| 29.3| 22.7| 13.3| 36.2| 94.4| 91.1|flag_ohio.gif|http://www.ohio.gov/
+Oklahoma| 3450654| 25.9| 10.3| 28.3| 22.3| 13.2| 35.5| 96.6| 93.8|flag_oklahoma.gif|http://www.oklahoma.gov/
+Oregon| 3421399| 24.7| 9.6| 29.1| 23.7| 12.8| 36.3| 98.4| 96.2|flag_oregon.gif|http://www.oregon.gov/
+Pennsylvania| 12281054| 23.8| 8.9| 28.6| 23.1| 15.6| 38.0| 93.4| 89.9|flag_pennsylvania.gif|http://www.pennsylvania.gov/
+Rhode Island| 1048319| 23.6| 10.2| 29.6| 22.0| 14.5| 36.7| 92.5| 88.8|flag_rhodeisland.gif|http://www.rhodeisland.gov/
+South Carolina| 4012012| 25.2| 10.2| 29.6| 23.0| 12.1| 35.4| 94.5| 91.2|flag_southcarolina.gif|http://www.southcarolina.gov/
+South Dakota| 754844| 26.8| 10.3| 27.3| 21.2| 14.3| 35.6| 98.5| 96.1|flag_southdakota.gif|http://www.southdakota.gov/
+Tennessee| 5689283| 24.6| 9.6| 30.2| 23.2| 12.4| 35.9| 94.9| 91.6|flag_tennessee.gif|http://www.tennessee.gov/
+Texas| 20851820| 28.2| 10.5| 31.1| 20.2| 9.9| 32.3| 98.6| 96.2|flag_texas.gif|http://www.texas.gov/
+Utah| 2233169| 32.2| 14.2| 28.1| 17.0| 8.5| 27.1| 100.4| 97.9|flag_utah.gif|http://www.utah.gov/
+Vermont| 608827| 24.2| 9.3| 29.0| 24.8| 12.7| 37.7| 96.1| 93.3|flag_vermont.gif|http://www.vermont.gov/
+Virginia| 7078515| 24.6| 9.6| 31.6| 23.0| 11.2| 35.7| 96.3| 93.7|flag_virginia.gif|http://www.virginia.gov/
+Washington| 5894121| 25.7| 9.5| 30.8| 22.8| 11.2| 35.3| 99.1| 97.0|flag_washington.gif|http://www.washington.gov/
+West Virginia| 1808344| 22.3| 9.5| 27.7| 25.2| 15.3| 38.9| 94.6| 91.7|flag_westvirginia.gif|http://www.west virginia.gov/
+Wisconsin| 5363675| 25.5| 9.7| 29.5| 22.2| 13.1| 36.0| 97.6| 95.1|flag_wisconsin.gif|http://www.wisconsin.gov/
+Wyoming| 493782| 26.1| 10.1| 28.1| 24.0| 11.7| 36.2| 101.2| 99.7|flag_wyoming.gif|http://www.wyoming.gov/
+Puerto Rico| 3808610| 28.7| 11.3| 27.6| 21.3| 11.2| 32.1| 92.8| 88.4|flag_puertorico.gif|http://www.gobierno.pr/
@@ -0,0 +1,54 @@
+Geographic area;Total population;Under 18 years;18 to 24 years;25 to 44 years;45 to 64 years;65 years and over;Median age (years);All ages;18 years and over;Flag;Website
+United States; 281421906; 25.7; 9.6; 30.2; 22.0; 12.4; 35.3; 96.3; 93.4;flag_unitedstates.gif; http://www.usa.gov/
+Alabama; 4447100; 25.3; 9.9; 29.0; 22.8; 13.0; 35.8; 93.3; 89.6;flag_alabama.gif; http://www.alabama.gov/
+Alaska; 626932; 30.4; 9.1; 32.5; 22.3; 5.7; 32.4; 107.0; 107.6;flag_alaska.gif;http://www.alaska.gov/
+Arizona; 5130632; 26.6; 10.0; 29.5; 20.9; 13.0; 34.2; 99.7; 97.7;flag_arizona.gif;http://www.arizona.gov/
+Arkansas; 2673400; 25.4; 9.8; 28.1; 22.7; 14.0; 36.0; 95.3; 92.1;flag_arkansas.gif;http://www.arkansas.gov/
+California; 33871648; 27.3; 9.9; 31.6; 20.5; 10.6; 33.3; 99.3; 97.1;flag_california.gif;http://www.california.gov/
+Colorado; 4301261; 25.6; 10.0; 32.6; 22.2; 9.7; 34.3; 101.4; 100.0;flag_colorado.gif;http://www.colorado.gov/
+Connecticut; 3405565; 24.7; 8.0; 30.3; 23.2; 13.8; 37.4; 93.9; 90.5;flag_connecticut.gif;http://www.connecticut.gov/
+Delaware; 783600; 24.8; 9.6; 30.2; 22.4; 13.0; 36.0; 94.4; 91.0;flag_delaware.gif;http://www.delaware.gov/
+District of Columbia; 572059; 20.1; 12.7; 33.1; 21.9; 12.2; 34.6; 89.0; 86.1;;http://www.districtofcolumbia.gov/
+Florida; 15982378; 22.8; 8.3; 28.6; 22.7; 17.6; 38.7; 95.3; 92.5;flag_florida.gif;http://www.florida.gov/
+Georgia; 8186453; 26.5; 10.2; 32.4; 21.3; 9.6; 33.4; 96.8; 94.0;flag_georgia.gif;http://www.georgia.gov/
+Hawaii; 1211537; 24.4; 9.5; 29.9; 22.9; 13.3; 36.2; 101.0; 99.4;flag_hawaii.gif;http://www.hawaii.gov/
+Idaho; 1293953; 28.5; 10.7; 28.0; 21.5; 11.3; 33.2; 100.5; 98.5;flag_idaho.gif;http://www.idaho.gov/
+Illinois; 12419293; 26.1; 9.8; 30.6; 21.5; 12.1; 34.7; 95.9; 92.9;flag_illinois.gif;http://www.illinois.gov/
+Indiana; 6080485; 25.9; 10.1; 29.5; 22.1; 12.4; 35.2; 96.3; 93.3;flag_indiana.gif;http://www.indiana.gov/
+Iowa; 2926324; 25.1; 10.2; 27.6; 22.2; 14.9; 36.6; 96.3; 93.4;flag_iowa.gif;http://www.iowa.gov/
+Kansas; 2688418; 26.5; 10.3; 28.6; 21.4; 13.3; 35.2; 97.7; 95.0;flag_kansas.gif;http://www.kansas.gov/
+Kentucky; 4041769; 24.6; 9.9; 30.0; 23.0; 12.5; 35.9; 95.6; 92.5;flag_kentucky.gif;http://www.kentucky.gov/
+Louisiana; 4468976; 27.3; 10.6; 28.9; 21.6; 11.6; 34.0; 93.8; 90.1;flag_louisiana.gif;http://www.louisiana.gov/
+Maine; 1274923; 23.6; 8.1; 29.1; 24.8; 14.4; 38.6; 94.8; 91.7;flag_maine.gif;http://www.maine.gov/
+Maryland; 5296486; 25.6; 8.5; 31.4; 23.1; 11.3; 36.0; 93.4; 89.8;flag_maryland.gif;http://www.maryland.gov/
+Massachusetts; 6349097; 23.6; 9.1; 31.3; 22.4; 13.5; 36.5; 93.0; 89.5;flag_massachusetts.gif;http://www.massachusetts.gov/
+Michigan; 9938444; 26.1; 9.4; 29.8; 22.4; 12.3; 35.5; 96.2; 93.2;flag_michigan.gif;http://www.michigan.gov/
+Minnesota; 4919479; 26.2; 9.6; 30.4; 21.8; 12.1; 35.4; 98.1; 95.6;flag_minnesota.gif;http://www.minnesota.gov/
+Mississippi; 2844658; 27.3; 10.9; 28.4; 21.4; 12.1; 33.8; 93.4; 89.6;flag_mississippi.gif;http://www.mississippi.gov/
+Missouri; 5595211; 25.5; 9.6; 29.1; 22.3; 13.5; 36.1; 94.6; 91.3;flag_missouri.gif;http://www.missouri.gov/
+Montana; 902195; 25.5; 9.5; 27.2; 24.4; 13.4; 37.5; 99.3; 97.2;flag_montana.gif;http://www.montana.gov/
+Nebraska; 1711263; 26.3; 10.2; 28.5; 21.5; 13.6; 35.3; 97.2; 94.6;flag_nebraska.gif;http://www.nebraska.gov/
+Nevada; 1998257; 25.6; 9.0; 31.5; 23.0; 11.0; 35.0; 103.9; 103.2;flag_nevada.gif;http://www.nevada.gov/
+New Hampshire; 1235786; 25.0; 8.4; 30.9; 23.8; 12.0; 37.1; 96.8; 94.1;flag_newhampshire.gif;http://www.newhampshire.gov/
+New Jersey; 8414350; 24.8; 8.0; 31.2; 22.7; 13.2; 36.7; 94.3; 90.9;flag_newjersey.gif;http://www.newjersey.gov/
+New Mexico; 1819046; 28.0; 9.8; 28.4; 22.2; 11.7; 34.6; 96.7; 94.0;flag_newmexico.gif;http://www.newmexico.gov/
+New York; 18976457; 24.7; 9.3; 30.7; 22.3; 12.9; 35.9; 93.1; 89.4;flag_newyork.gif;http://www.newyork.gov/
+North Carolina; 8049313; 24.4; 10.0; 31.1; 22.5; 12.0; 35.3; 96.0; 93.3;flag_northcarolina.gif;http://www.northcarolina.gov/
+North Dakota; 642200; 25.0; 11.4; 27.2; 21.6; 14.7; 36.2; 99.6; 97.8;flag_northdakota.gif;http://www.northdakota.gov/
+Ohio; 11353140; 25.4; 9.3; 29.3; 22.7; 13.3; 36.2; 94.4; 91.1;flag_ohio.gif;http://www.ohio.gov/
+Oklahoma; 3450654; 25.9; 10.3; 28.3; 22.3; 13.2; 35.5; 96.6; 93.8;flag_oklahoma.gif;http://www.oklahoma.gov/
+Oregon; 3421399; 24.7; 9.6; 29.1; 23.7; 12.8; 36.3; 98.4; 96.2;flag_oregon.gif;http://www.oregon.gov/
+Pennsylvania; 12281054; 23.8; 8.9; 28.6; 23.1; 15.6; 38.0; 93.4; 89.9;flag_pennsylvania.gif;http://www.pennsylvania.gov/
+Rhode Island; 1048319; 23.6; 10.2; 29.6; 22.0; 14.5; 36.7; 92.5; 88.8;flag_rhodeisland.gif;http://www.rhodeisland.gov/
+South Carolina; 4012012; 25.2; 10.2; 29.6; 23.0; 12.1; 35.4; 94.5; 91.2;flag_southcarolina.gif;http://www.southcarolina.gov/
+South Dakota; 754844; 26.8; 10.3; 27.3; 21.2; 14.3; 35.6; 98.5; 96.1;flag_southdakota.gif;http://www.southdakota.gov/
+Tennessee; 5689283; 24.6; 9.6; 30.2; 23.2; 12.4; 35.9; 94.9; 91.6;flag_tennessee.gif;http://www.tennessee.gov/
+Texas; 20851820; 28.2; 10.5; 31.1; 20.2; 9.9; 32.3; 98.6; 96.2;flag_texas.gif;http://www.texas.gov/
+Utah; 2233169; 32.2; 14.2; 28.1; 17.0; 8.5; 27.1; 100.4; 97.9;flag_utah.gif;http://www.utah.gov/
+Vermont; 608827; 24.2; 9.3; 29.0; 24.8; 12.7; 37.7; 96.1; 93.3;flag_vermont.gif;http://www.vermont.gov/
+Virginia; 7078515; 24.6; 9.6; 31.6; 23.0; 11.2; 35.7; 96.3; 93.7;flag_virginia.gif;http://www.virginia.gov/
+Washington; 5894121; 25.7; 9.5; 30.8; 22.8; 11.2; 35.3; 99.1; 97.0;flag_washington.gif;http://www.washington.gov/
+West Virginia; 1808344; 22.3; 9.5; 27.7; 25.2; 15.3; 38.9; 94.6; 91.7;flag_westvirginia.gif;http://www.west virginia.gov/
+Wisconsin; 5363675; 25.5; 9.7; 29.5; 22.2; 13.1; 36.0; 97.6; 95.1;flag_wisconsin.gif;http://www.wisconsin.gov/
+Wyoming; 493782; 26.1; 10.1; 28.1; 24.0; 11.7; 36.2; 101.2; 99.7;flag_wyoming.gif;http://www.wyoming.gov/
+Puerto Rico; 3808610; 28.7; 11.3; 27.6; 21.3; 11.2; 32.1; 92.8; 88.4;flag_puertorico.gif;http://www.gobierno.pr/
View
@@ -2,14 +2,16 @@
require File.join(File.expand_path(File.dirname(__FILE__)), '..', 'lib', 'csv2json.rb') # this form is important for local development
class TestCsv2json < Test::Unit::TestCase
+ SEPS = {:comma => ',', :pipe => '|', :semicolon => ';'}
should "parse some test files" do
fixtures_dir = File.expand_path(File.join(File.dirname(__FILE__), 'fixtures'))
Dir.chdir(fixtures_dir) do
Dir.glob('*.csv') do |filename|
- json_template = File.basename(filename, ".csv")+'.json'
+ filename_parts = File.basename(filename, ".csv").split('_')
+ json_template = filename_parts[0] + '.json'
File.open(filename, "r") do |input|
output = StringIO.new()
- CSV2JSON.parse(input, output)
+ CSV2JSON.parse(input, output, nil, :col_sep => SEPS[filename_parts[1].to_sym] )
template = File.read(json_template)
output.pos = 0
assert template == output.read

0 comments on commit 0818218

Please sign in to comment.