csv-hash 0.1.0 → 0.1.1
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.rdoc +12 -1
- data/VERSION +1 -1
- data/csv-hash.gemspec +60 -0
- data/lib/csv-hash.rb +2 -1
- data/spec/assets/clean_test.csv +3 -0
- data/spec/assets/test.csv +3 -0
- metadata +5 -2
data/README.rdoc
CHANGED
@@ -1,6 +1,17 @@
|
|
1
1
|
= csv-hash
|
2
2
|
|
3
|
-
|
3
|
+
Will import a CSV as an array of hashes. Or will export a CSV from an array of hashes (if given a column list).
|
4
|
+
|
5
|
+
|
6
|
+
== Usage
|
7
|
+
|
8
|
+
=== Parse a csv to an array of hashes
|
9
|
+
CSVHash('path_to_csv.csv')
|
10
|
+
|
11
|
+
Note the hash will have strings for keys
|
12
|
+
|
13
|
+
=== Generate a string from an array of hashes and a column list
|
14
|
+
CSVHash(array_of_hashes,[:column,"names","in",:order])
|
4
15
|
|
5
16
|
== Note on Patches/Pull Requests
|
6
17
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.1
|
data/csv-hash.gemspec
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{csv-hash}
|
8
|
+
s.version = "0.1.1"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Tal Atlas"]
|
12
|
+
s.date = %q{2010-05-26}
|
13
|
+
s.description = %q{Will import a CSV as an array of hashes. Or will export a CSV from an array of hashes (if given a column list).}
|
14
|
+
s.email = %q{me@talatlas.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".gitignore",
|
22
|
+
"LICENSE",
|
23
|
+
"README.rdoc",
|
24
|
+
"Rakefile",
|
25
|
+
"VERSION",
|
26
|
+
"csv-hash.gemspec",
|
27
|
+
"lib/csv-hash.rb",
|
28
|
+
"spec/assets/clean_test.csv",
|
29
|
+
"spec/assets/test.csv",
|
30
|
+
"spec/csv-hash_spec.rb",
|
31
|
+
"spec/spec.opts",
|
32
|
+
"spec/spec_helper.rb"
|
33
|
+
]
|
34
|
+
s.homepage = %q{http://github.com/Talby/csv-hash}
|
35
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
36
|
+
s.require_paths = ["lib"]
|
37
|
+
s.rubygems_version = %q{1.3.6}
|
38
|
+
s.summary = %q{A gem for interacting with CSVs as hashes}
|
39
|
+
s.test_files = [
|
40
|
+
"spec/csv-hash_spec.rb",
|
41
|
+
"spec/spec_helper.rb"
|
42
|
+
]
|
43
|
+
|
44
|
+
if s.respond_to? :specification_version then
|
45
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
46
|
+
s.specification_version = 3
|
47
|
+
|
48
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
49
|
+
s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
|
50
|
+
s.add_runtime_dependency(%q<fastercsv>, [">= 1.5.0"])
|
51
|
+
else
|
52
|
+
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
53
|
+
s.add_dependency(%q<fastercsv>, [">= 1.5.0"])
|
54
|
+
end
|
55
|
+
else
|
56
|
+
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
57
|
+
s.add_dependency(%q<fastercsv>, [">= 1.5.0"])
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
data/lib/csv-hash.rb
CHANGED
@@ -44,7 +44,7 @@ module CSVHash
|
|
44
44
|
def to_string hashes, columns
|
45
45
|
rows = hashes.collect do |hash|
|
46
46
|
vals = columns.collect do |col|
|
47
|
-
sp = col.split('__')
|
47
|
+
sp = col.to_s.split('__')
|
48
48
|
ret = hash
|
49
49
|
sp.each do |key|
|
50
50
|
puts key unless ret
|
@@ -66,6 +66,7 @@ module CSVHash
|
|
66
66
|
end
|
67
67
|
end
|
68
68
|
|
69
|
+
# Pass either a path to a csv file to parse which will return an array of hashes (stringified keys) or pass an array of hashes and an array of column names
|
69
70
|
def CSVHash arg, columns=nil
|
70
71
|
if arg.is_a?(File)
|
71
72
|
CSVHash.from_file(arg.path)
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
version: 0.1.
|
8
|
+
- 1
|
9
|
+
version: 0.1.1
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Tal Atlas
|
@@ -61,7 +61,10 @@ files:
|
|
61
61
|
- README.rdoc
|
62
62
|
- Rakefile
|
63
63
|
- VERSION
|
64
|
+
- csv-hash.gemspec
|
64
65
|
- lib/csv-hash.rb
|
66
|
+
- spec/assets/clean_test.csv
|
67
|
+
- spec/assets/test.csv
|
65
68
|
- spec/csv-hash_spec.rb
|
66
69
|
- spec/spec.opts
|
67
70
|
- spec/spec_helper.rb
|