csv2json 0.1.1 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +12 -11
- data/Rakefile +1 -1
- data/bin/csv2json +7 -2
- data/csv2json.gemspec +13 -7
- data/lib/csv2json-version.rb +1 -1
- data/lib/csv2json.rb +3 -3
- data/test/fixtures/{addresses.csv → addresses_comma.csv} +0 -0
- data/test/fixtures/addresses_pipe.csv +16 -0
- data/test/fixtures/addresses_semicolon.csv +16 -0
- data/test/fixtures/{photos.csv → photos_comma.csv} +0 -0
- data/test/fixtures/photos_pipe.csv +13 -0
- data/test/fixtures/photos_semicolon.csv +13 -0
- data/test/fixtures/{population.csv → population_comma.csv} +0 -0
- data/test/fixtures/population_pipe.csv +54 -0
- data/test/fixtures/population_semicolon.csv +54 -0
- data/test/test_csv2json.rb +4 -2
- metadata +40 -20
data/README.md
CHANGED
@@ -46,13 +46,14 @@ gets turned into this JSON:
|
|
46
46
|
|
47
47
|
### Installation
|
48
48
|
|
49
|
-
`sudo gem install csv2json --source
|
49
|
+
`sudo gem install csv2json --source http://rubygems.org`
|
50
50
|
|
51
51
|
### Usage
|
52
52
|
|
53
53
|
Usage: csv2json [INPUT] [OPTIONS]
|
54
54
|
|
55
55
|
Specific options:
|
56
|
+
-s, --separator SEP Set separator character surrounded by single quotes (default is ',')
|
56
57
|
-o, --output FILE Write output to a file
|
57
58
|
-h, --help Show this message
|
58
59
|
-v, --version Show version
|
@@ -88,18 +89,18 @@ or in-memory
|
|
88
89
|
output.pos = 0
|
89
90
|
puts output.read
|
90
91
|
|
92
|
+
## Authors
|
93
|
+
|
94
|
+
* **Antonin Hildebrand** ([http://binaryage.com](http://binaryage.com))
|
95
|
+
* **Rafael Souza** ([http://github.com/rafaels](http://github.com/rafaels))
|
96
|
+
|
97
|
+
---
|
98
|
+
|
91
99
|
## Want to contribute?
|
92
|
-
|
100
|
+
|
93
101
|
* Fork the project.
|
94
102
|
* Make your feature addition or bug fix.
|
95
|
-
* Add tests for it. This is important so I don't break it in a
|
96
|
-
future version unintentionally.
|
103
|
+
* Add tests for it. This is important so I don't break it in a future version unintentionally.
|
97
104
|
* Commit, do not mess with rakefile, version, or history.
|
98
105
|
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
99
|
-
* Send me a pull request. Bonus points for topic branches.
|
100
|
-
|
101
|
-
## Copyright
|
102
|
-
|
103
|
-
Copyright (c) 2009 Antonin Hildebrand. See LICENSE for details.
|
104
|
-
|
105
|
-
Check out [http://binaryage.com](http://binaryage.com)
|
106
|
+
* Send me a pull request. Bonus points for topic branches.
|
data/Rakefile
CHANGED
@@ -11,7 +11,7 @@ begin
|
|
11
11
|
gem.description = %Q{handy for converting xls files to json}
|
12
12
|
gem.email = "antonin@hildebrand.cz"
|
13
13
|
gem.homepage = "http://github.com/darwin/csv2json"
|
14
|
-
gem.authors = ["Antonin Hildebrand"]
|
14
|
+
gem.authors = ["Antonin Hildebrand", "Rafael Souza"]
|
15
15
|
gem.add_dependency "json"
|
16
16
|
gem.add_dependency "fastercsv"
|
17
17
|
gem.add_development_dependency "shoulda", ">= 0"
|
data/bin/csv2json
CHANGED
@@ -13,12 +13,17 @@ module CSV2JSONRunner
|
|
13
13
|
|
14
14
|
options = OpenStruct.new
|
15
15
|
options.output = "-"
|
16
|
+
options.separator = ","
|
16
17
|
|
17
18
|
opts = OptionParser.new do |o|
|
18
19
|
o.banner = USAGE
|
19
20
|
o.separator ""
|
20
21
|
o.separator "Specific options:"
|
21
22
|
|
23
|
+
o.on("-s", "--separator SEP", "Set separator character surrounded by single quotes (default is ',')") do |sep|
|
24
|
+
options.separator = sep
|
25
|
+
end
|
26
|
+
|
22
27
|
o.on("-o", "--output FILE", "Write output to a file") do |fn|
|
23
28
|
options.output = fn
|
24
29
|
end
|
@@ -54,8 +59,8 @@ module CSV2JSONRunner
|
|
54
59
|
end
|
55
60
|
|
56
61
|
# run the command
|
57
|
-
CSV2JSON.parse(IN, OUT)
|
62
|
+
CSV2JSON.parse(IN, OUT, nil, :col_sep => options.separator)
|
58
63
|
|
59
64
|
# leave in peace
|
60
65
|
OUT.flush
|
61
|
-
end
|
66
|
+
end
|
data/csv2json.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{csv2json}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.2.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
-
s.authors = ["Antonin Hildebrand"]
|
12
|
-
s.date = %q{
|
11
|
+
s.authors = ["Antonin Hildebrand", "Rafael Souza"]
|
12
|
+
s.date = %q{2010-03-14}
|
13
13
|
s.default_executable = %q{csv2json}
|
14
14
|
s.description = %q{handy for converting xls files to json}
|
15
15
|
s.email = %q{antonin@hildebrand.cz}
|
@@ -28,19 +28,25 @@ Gem::Specification.new do |s|
|
|
28
28
|
"csv2json.gemspec",
|
29
29
|
"lib/csv2json-version.rb",
|
30
30
|
"lib/csv2json.rb",
|
31
|
-
"test/fixtures/addresses.csv",
|
32
31
|
"test/fixtures/addresses.json",
|
33
|
-
"test/fixtures/
|
32
|
+
"test/fixtures/addresses_comma.csv",
|
33
|
+
"test/fixtures/addresses_pipe.csv",
|
34
|
+
"test/fixtures/addresses_semicolon.csv",
|
34
35
|
"test/fixtures/photos.json",
|
35
|
-
"test/fixtures/
|
36
|
+
"test/fixtures/photos_comma.csv",
|
37
|
+
"test/fixtures/photos_pipe.csv",
|
38
|
+
"test/fixtures/photos_semicolon.csv",
|
36
39
|
"test/fixtures/population.json",
|
40
|
+
"test/fixtures/population_comma.csv",
|
41
|
+
"test/fixtures/population_pipe.csv",
|
42
|
+
"test/fixtures/population_semicolon.csv",
|
37
43
|
"test/helper.rb",
|
38
44
|
"test/test_csv2json.rb"
|
39
45
|
]
|
40
46
|
s.homepage = %q{http://github.com/darwin/csv2json}
|
41
47
|
s.rdoc_options = ["--charset=UTF-8"]
|
42
48
|
s.require_paths = ["lib"]
|
43
|
-
s.rubygems_version = %q{1.3.
|
49
|
+
s.rubygems_version = %q{1.3.6}
|
44
50
|
s.summary = %q{.csv to .json converter}
|
45
51
|
s.test_files = [
|
46
52
|
"test/helper.rb",
|
data/lib/csv2json-version.rb
CHANGED
data/lib/csv2json.rb
CHANGED
@@ -11,10 +11,10 @@ module CSV2JSON
|
|
11
11
|
end
|
12
12
|
|
13
13
|
# input and output are file objects, you can use StringIO if you want to work in memory
|
14
|
-
def parse(input, output, headers=nil)
|
14
|
+
def parse(input, output, headers=nil, options={})
|
15
15
|
result = Array.new
|
16
16
|
|
17
|
-
FasterCSV.new(input).each do |row|
|
17
|
+
FasterCSV.new(input, options).each do |row|
|
18
18
|
# treat first row as headers if the caller didn't provide them
|
19
19
|
unless headers
|
20
20
|
headers = row
|
@@ -33,4 +33,4 @@ module CSV2JSON
|
|
33
33
|
module_function :parse
|
34
34
|
module_function :convert
|
35
35
|
|
36
|
-
end
|
36
|
+
end
|
File without changes
|
@@ -0,0 +1,16 @@
|
|
1
|
+
Office|Address1|Address2|Address3|City|State|Zip|Phone|Fax
|
2
|
+
Headquarters|1600 Amphitheatre Parkway|||Mountain View|CA|94043|650-253-0000|650-253-0001
|
3
|
+
New York Sales & Engineering Office|76 Ninth Avenue|||New York|NY|10011|212-565-0000|212-565-0001
|
4
|
+
Ann Arbor Sales Office|201 South Division Street|||Ann Arbor|MI|48104|734-332-6500|734-332-6501
|
5
|
+
Atlanta Sales & Engineering Office|10 10th Street NE|||Atlanta|GA|30309|404-487-9000|404-487-9001
|
6
|
+
Boulder Sales & Engineering Office|2590 Pearl St.|||Boulder|CO|80302|303-245-0086|303-535-5592
|
7
|
+
Cambridge Sales & Engineering Office|5 Cambridge Center|||Cambridge|MA|02142|617-682-3635|617-249-0199
|
8
|
+
Chicago Sales & Engineering Office|20 West Kinzie St.|||Chicago|IL|60610|312-840-4100|312-840-4101
|
9
|
+
Coppell Sales Office|701 Canyon Drive|||Coppell|TX|75019|214-451-4000|214-451-4001
|
10
|
+
Detroit Sales Office|114 Willits Street|||Birmingham|MI|48009|248-351-6220|248-351-6227
|
11
|
+
Irvine Sales & Engineering Office|19540 Jamboree Road|||Irvine|CA|92612|949-794-1600|949-794-1601
|
12
|
+
Pittsburgh Engineering Office|4720 Forbes Avenue|||Pittsburgh|PA|15213||
|
13
|
+
Santa Monica Sales & Engineering Office|604 Arizona Avenue|||Santa Monica|CA|90401|310-460-4000|310-309-6840
|
14
|
+
Seattle Engineering Office|720 4th Avenue|||Kirkland|WA|98033|425-739-5600|425-739-5601
|
15
|
+
Seattle Sales Office|501 N. 34th Street|||Seattle|WA|98103|206-876-1500|206-876-1501
|
16
|
+
Washington D.C. Public Policy Office|1001 Pennsylvania Avenue NW|||Washington|DC|20004|202-742-6520|
|
@@ -0,0 +1,16 @@
|
|
1
|
+
Office;Address1;Address2;Address3;City;State;Zip;Phone;Fax
|
2
|
+
Headquarters;1600 Amphitheatre Parkway;;;Mountain View;CA;94043;650-253-0000;650-253-0001
|
3
|
+
New York Sales & Engineering Office;76 Ninth Avenue;;;New York;NY;10011;212-565-0000;212-565-0001
|
4
|
+
Ann Arbor Sales Office;201 South Division Street;;;Ann Arbor;MI;48104;734-332-6500;734-332-6501
|
5
|
+
Atlanta Sales & Engineering Office;10 10th Street NE;;;Atlanta;GA;30309;404-487-9000;404-487-9001
|
6
|
+
Boulder Sales & Engineering Office;2590 Pearl St.;;;Boulder;CO;80302;303-245-0086;303-535-5592
|
7
|
+
Cambridge Sales & Engineering Office;5 Cambridge Center;;;Cambridge;MA;02142;617-682-3635;617-249-0199
|
8
|
+
Chicago Sales & Engineering Office;20 West Kinzie St.;;;Chicago;IL;60610;312-840-4100;312-840-4101
|
9
|
+
Coppell Sales Office;701 Canyon Drive;;;Coppell;TX;75019;214-451-4000;214-451-4001
|
10
|
+
Detroit Sales Office;114 Willits Street;;;Birmingham;MI;48009;248-351-6220;248-351-6227
|
11
|
+
Irvine Sales & Engineering Office;19540 Jamboree Road;;;Irvine;CA;92612;949-794-1600;949-794-1601
|
12
|
+
Pittsburgh Engineering Office;4720 Forbes Avenue;;;Pittsburgh;PA;15213;;
|
13
|
+
Santa Monica Sales & Engineering Office;604 Arizona Avenue;;;Santa Monica;CA;90401;310-460-4000;310-309-6840
|
14
|
+
Seattle Engineering Office;720 4th Avenue;;;Kirkland;WA;98033;425-739-5600;425-739-5601
|
15
|
+
Seattle Sales Office;501 N. 34th Street;;;Seattle;WA;98103;206-876-1500;206-876-1501
|
16
|
+
Washington D.C. Public Policy Office;1001 Pennsylvania Avenue NW;;;Washington;DC;20004;202-742-6520;
|
File without changes
|
@@ -0,0 +1,13 @@
|
|
1
|
+
thumbpath|imgpath|imgsrc|width|height|thumbsrc|thumbwidth|thumbheight
|
2
|
+
thumbnails/|images/|paris_01.jpg|350|262|paris_01.jpg|75|56
|
3
|
+
thumbnails/|images/|paris_02.jpg|262|350|paris_02.jpg|75|56
|
4
|
+
thumbnails/|images/|paris_03.jpg|350|262|paris_03.jpg|75|56
|
5
|
+
thumbnails/|images/|paris_04.jpg|262|350|paris_04.jpg|56|75
|
6
|
+
thumbnails/|images/|paris_05.jpg|262|350|paris_05.jpg|56|75
|
7
|
+
thumbnails/|images/|paris_06.jpg|350|262|paris_06.jpg|75|56
|
8
|
+
thumbnails/|images/|paris_07.jpg|262|350|paris_07.jpg|56|75
|
9
|
+
thumbnails/|images/|paris_08.jpg|262|350|paris_08.jpg|56|75
|
10
|
+
thumbnails/|images/|paris_09.jpg|262|350|paris_09.jpg|56|75
|
11
|
+
thumbnails/|images/|paris_10.jpg|350|262|paris_10.jpg|75|56
|
12
|
+
thumbnails/|images/|paris_11.jpg|350|262|paris_11.jpg|75|56
|
13
|
+
thumbnails/|images/|paris_12.jpg|350|262|paris_12.jpg|75|56
|
@@ -0,0 +1,13 @@
|
|
1
|
+
thumbpath;imgpath;imgsrc;width;height;thumbsrc;thumbwidth;thumbheight
|
2
|
+
thumbnails/;images/;paris_01.jpg;350;262;paris_01.jpg;75;56
|
3
|
+
thumbnails/;images/;paris_02.jpg;262;350;paris_02.jpg;75;56
|
4
|
+
thumbnails/;images/;paris_03.jpg;350;262;paris_03.jpg;75;56
|
5
|
+
thumbnails/;images/;paris_04.jpg;262;350;paris_04.jpg;56;75
|
6
|
+
thumbnails/;images/;paris_05.jpg;262;350;paris_05.jpg;56;75
|
7
|
+
thumbnails/;images/;paris_06.jpg;350;262;paris_06.jpg;75;56
|
8
|
+
thumbnails/;images/;paris_07.jpg;262;350;paris_07.jpg;56;75
|
9
|
+
thumbnails/;images/;paris_08.jpg;262;350;paris_08.jpg;56;75
|
10
|
+
thumbnails/;images/;paris_09.jpg;262;350;paris_09.jpg;56;75
|
11
|
+
thumbnails/;images/;paris_10.jpg;350;262;paris_10.jpg;75;56
|
12
|
+
thumbnails/;images/;paris_11.jpg;350;262;paris_11.jpg;75;56
|
13
|
+
thumbnails/;images/;paris_12.jpg;350;262;paris_12.jpg;75;56
|
File without changes
|
@@ -0,0 +1,54 @@
|
|
1
|
+
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
|
2
|
+
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/
|
3
|
+
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/
|
4
|
+
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/
|
5
|
+
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/
|
6
|
+
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/
|
7
|
+
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/
|
8
|
+
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/
|
9
|
+
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/
|
10
|
+
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/
|
11
|
+
District of Columbia| 572059| 20.1| 12.7| 33.1| 21.9| 12.2| 34.6| 89.0| 86.1||http://www.districtofcolumbia.gov/
|
12
|
+
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/
|
13
|
+
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/
|
14
|
+
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/
|
15
|
+
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/
|
16
|
+
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/
|
17
|
+
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/
|
18
|
+
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/
|
19
|
+
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/
|
20
|
+
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/
|
21
|
+
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/
|
22
|
+
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/
|
23
|
+
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/
|
24
|
+
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/
|
25
|
+
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/
|
26
|
+
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/
|
27
|
+
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/
|
28
|
+
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/
|
29
|
+
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/
|
30
|
+
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/
|
31
|
+
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/
|
32
|
+
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/
|
33
|
+
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/
|
34
|
+
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/
|
35
|
+
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/
|
36
|
+
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/
|
37
|
+
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/
|
38
|
+
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/
|
39
|
+
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/
|
40
|
+
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/
|
41
|
+
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/
|
42
|
+
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/
|
43
|
+
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/
|
44
|
+
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/
|
45
|
+
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/
|
46
|
+
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/
|
47
|
+
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/
|
48
|
+
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/
|
49
|
+
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/
|
50
|
+
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/
|
51
|
+
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/
|
52
|
+
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/
|
53
|
+
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/
|
54
|
+
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 @@
|
|
1
|
+
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
|
2
|
+
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/
|
3
|
+
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/
|
4
|
+
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/
|
5
|
+
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/
|
6
|
+
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/
|
7
|
+
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/
|
8
|
+
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/
|
9
|
+
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/
|
10
|
+
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/
|
11
|
+
District of Columbia; 572059; 20.1; 12.7; 33.1; 21.9; 12.2; 34.6; 89.0; 86.1;;http://www.districtofcolumbia.gov/
|
12
|
+
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/
|
13
|
+
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/
|
14
|
+
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/
|
15
|
+
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/
|
16
|
+
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/
|
17
|
+
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/
|
18
|
+
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/
|
19
|
+
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/
|
20
|
+
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/
|
21
|
+
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/
|
22
|
+
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/
|
23
|
+
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/
|
24
|
+
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/
|
25
|
+
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/
|
26
|
+
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/
|
27
|
+
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/
|
28
|
+
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/
|
29
|
+
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/
|
30
|
+
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/
|
31
|
+
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/
|
32
|
+
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/
|
33
|
+
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/
|
34
|
+
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/
|
35
|
+
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/
|
36
|
+
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/
|
37
|
+
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/
|
38
|
+
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/
|
39
|
+
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/
|
40
|
+
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/
|
41
|
+
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/
|
42
|
+
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/
|
43
|
+
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/
|
44
|
+
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/
|
45
|
+
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/
|
46
|
+
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/
|
47
|
+
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/
|
48
|
+
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/
|
49
|
+
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/
|
50
|
+
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/
|
51
|
+
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/
|
52
|
+
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/
|
53
|
+
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/
|
54
|
+
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/
|
data/test/test_csv2json.rb
CHANGED
@@ -2,14 +2,16 @@ require 'helper'
|
|
2
2
|
require File.join(File.expand_path(File.dirname(__FILE__)), '..', 'lib', 'csv2json.rb') # this form is important for local development
|
3
3
|
|
4
4
|
class TestCsv2json < Test::Unit::TestCase
|
5
|
+
SEPS = {:comma => ',', :pipe => '|', :semicolon => ';'}
|
5
6
|
should "parse some test files" do
|
6
7
|
fixtures_dir = File.expand_path(File.join(File.dirname(__FILE__), 'fixtures'))
|
7
8
|
Dir.chdir(fixtures_dir) do
|
8
9
|
Dir.glob('*.csv') do |filename|
|
9
|
-
|
10
|
+
filename_parts = File.basename(filename, ".csv").split('_')
|
11
|
+
json_template = filename_parts[0] + '.json'
|
10
12
|
File.open(filename, "r") do |input|
|
11
13
|
output = StringIO.new()
|
12
|
-
CSV2JSON.parse(input, output)
|
14
|
+
CSV2JSON.parse(input, output, nil, :col_sep => SEPS[filename_parts[1].to_sym] )
|
13
15
|
template = File.read(json_template)
|
14
16
|
output.pos = 0
|
15
17
|
assert template == output.read
|
metadata
CHANGED
@@ -1,47 +1,59 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: csv2json
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 2
|
8
|
+
- 0
|
9
|
+
version: 0.2.0
|
5
10
|
platform: ruby
|
6
11
|
authors:
|
7
12
|
- Antonin Hildebrand
|
13
|
+
- Rafael Souza
|
8
14
|
autorequire:
|
9
15
|
bindir: bin
|
10
16
|
cert_chain: []
|
11
17
|
|
12
|
-
date:
|
18
|
+
date: 2010-03-14 00:00:00 +01:00
|
13
19
|
default_executable: csv2json
|
14
20
|
dependencies:
|
15
21
|
- !ruby/object:Gem::Dependency
|
16
22
|
name: json
|
17
|
-
|
18
|
-
|
19
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
20
25
|
requirements:
|
21
26
|
- - ">="
|
22
27
|
- !ruby/object:Gem::Version
|
28
|
+
segments:
|
29
|
+
- 0
|
23
30
|
version: "0"
|
24
|
-
|
31
|
+
type: :runtime
|
32
|
+
version_requirements: *id001
|
25
33
|
- !ruby/object:Gem::Dependency
|
26
34
|
name: fastercsv
|
27
|
-
|
28
|
-
|
29
|
-
version_requirements: !ruby/object:Gem::Requirement
|
35
|
+
prerelease: false
|
36
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
30
37
|
requirements:
|
31
38
|
- - ">="
|
32
39
|
- !ruby/object:Gem::Version
|
40
|
+
segments:
|
41
|
+
- 0
|
33
42
|
version: "0"
|
34
|
-
|
43
|
+
type: :runtime
|
44
|
+
version_requirements: *id002
|
35
45
|
- !ruby/object:Gem::Dependency
|
36
46
|
name: shoulda
|
37
|
-
|
38
|
-
|
39
|
-
version_requirements: !ruby/object:Gem::Requirement
|
47
|
+
prerelease: false
|
48
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
40
49
|
requirements:
|
41
50
|
- - ">="
|
42
51
|
- !ruby/object:Gem::Version
|
52
|
+
segments:
|
53
|
+
- 0
|
43
54
|
version: "0"
|
44
|
-
|
55
|
+
type: :development
|
56
|
+
version_requirements: *id003
|
45
57
|
description: handy for converting xls files to json
|
46
58
|
email: antonin@hildebrand.cz
|
47
59
|
executables:
|
@@ -61,12 +73,18 @@ files:
|
|
61
73
|
- csv2json.gemspec
|
62
74
|
- lib/csv2json-version.rb
|
63
75
|
- lib/csv2json.rb
|
64
|
-
- test/fixtures/addresses.csv
|
65
76
|
- test/fixtures/addresses.json
|
66
|
-
- test/fixtures/
|
77
|
+
- test/fixtures/addresses_comma.csv
|
78
|
+
- test/fixtures/addresses_pipe.csv
|
79
|
+
- test/fixtures/addresses_semicolon.csv
|
67
80
|
- test/fixtures/photos.json
|
68
|
-
- test/fixtures/
|
81
|
+
- test/fixtures/photos_comma.csv
|
82
|
+
- test/fixtures/photos_pipe.csv
|
83
|
+
- test/fixtures/photos_semicolon.csv
|
69
84
|
- test/fixtures/population.json
|
85
|
+
- test/fixtures/population_comma.csv
|
86
|
+
- test/fixtures/population_pipe.csv
|
87
|
+
- test/fixtures/population_semicolon.csv
|
70
88
|
- test/helper.rb
|
71
89
|
- test/test_csv2json.rb
|
72
90
|
has_rdoc: true
|
@@ -82,18 +100,20 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
82
100
|
requirements:
|
83
101
|
- - ">="
|
84
102
|
- !ruby/object:Gem::Version
|
103
|
+
segments:
|
104
|
+
- 0
|
85
105
|
version: "0"
|
86
|
-
version:
|
87
106
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
88
107
|
requirements:
|
89
108
|
- - ">="
|
90
109
|
- !ruby/object:Gem::Version
|
110
|
+
segments:
|
111
|
+
- 0
|
91
112
|
version: "0"
|
92
|
-
version:
|
93
113
|
requirements: []
|
94
114
|
|
95
115
|
rubyforge_project:
|
96
|
-
rubygems_version: 1.3.
|
116
|
+
rubygems_version: 1.3.6
|
97
117
|
signing_key:
|
98
118
|
specification_version: 3
|
99
119
|
summary: .csv to .json converter
|