csv-hash 0.1.2 → 0.1.3
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.
- checksums.yaml +7 -0
- data/README.rdoc +28 -3
- data/Rakefile +1 -46
- data/csv-hash.gemspec +20 -56
- data/lib/csv-hash.rb +14 -12
- data/lib/csv_hash.rb +1 -0
- data/lib/csv_hash/version.rb +3 -0
- data/spec/spec_helper.rb +17 -6
- metadata +75 -74
- data/.document +0 -5
- data/VERSION +0 -1
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d6dc058b8873d8fd82b83bbe11bdd432d6cb63a7
|
4
|
+
data.tar.gz: fa3f2eeadec862204fc8a287df21f98090eef254
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a6e7a4f3625d91e61bf76004c4574310484a1f1f001cfc9a9c9e977249573b61215ab29897fe956763c349ca11ac7670bfca39388c26889ce4b5d051862fba35
|
7
|
+
data.tar.gz: f8d0244481d1744cb69fd0addf58261635d489051239fd96def7ad726fbbd048617c381178a5bc7fd37e4533937b2feea7789e6d172d8ae93a51d7017a404168
|
data/README.rdoc
CHANGED
@@ -6,12 +6,37 @@ Will import a CSV as an array of hashes. Or will export a CSV from an array of h
|
|
6
6
|
== Usage
|
7
7
|
|
8
8
|
=== Parse a csv to an array of hashes
|
9
|
-
CSVHash('path_to_csv.csv')
|
9
|
+
array_of_hashes, columns = CSVHash('path_to_csv.csv')
|
10
10
|
|
11
|
-
Note the hash will have strings for keys
|
11
|
+
Note the hash will have strings for keys and will remove all surrounding whitespace
|
12
12
|
|
13
13
|
=== Generate a string from an array of hashes and a column list
|
14
|
-
CSVHash(array_of_hashes,[:column,"names","in",:order])
|
14
|
+
string = CSVHash(array_of_hashes,[:column,"names","in",:order])
|
15
|
+
|
16
|
+
|
17
|
+
=== Nested Hashes
|
18
|
+
|
19
|
+
csv-hash supports nested hashes. A column tree of the structure (note the double underscore):
|
20
|
+
one,two__foo,two__bar__three,two__bar__four
|
21
|
+
1, 2, 3, 4,
|
22
|
+
|
23
|
+
will generate:
|
24
|
+
{
|
25
|
+
'one' => '1',
|
26
|
+
'two' => {
|
27
|
+
'foo' => '2',
|
28
|
+
'bar' => {'three' => '3', 'four' => '4'}
|
29
|
+
}
|
30
|
+
}
|
31
|
+
|
32
|
+
== Todo
|
33
|
+
|
34
|
+
* Remove dependency on Fast CSV
|
35
|
+
* Support auto column generation
|
36
|
+
* Generate hash of arrays
|
37
|
+
* Turn into CSVHash object which contains column structure and other metadata
|
38
|
+
* Sequel integration
|
39
|
+
* Arbitrary model support
|
15
40
|
|
16
41
|
== Note on Patches/Pull Requests
|
17
42
|
|
data/Rakefile
CHANGED
@@ -1,46 +1 @@
|
|
1
|
-
require
|
2
|
-
require 'rake'
|
3
|
-
|
4
|
-
begin
|
5
|
-
require 'jeweler'
|
6
|
-
Jeweler::Tasks.new do |gem|
|
7
|
-
gem.name = "csv-hash"
|
8
|
-
gem.summary = %Q{A gem for interacting with CSVs as hashes}
|
9
|
-
gem.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).}
|
10
|
-
gem.email = "me@talatlas.com"
|
11
|
-
gem.homepage = "http://github.com/Talby/csv-hash"
|
12
|
-
gem.authors = ["Tal Atlas"]
|
13
|
-
gem.add_development_dependency "rspec", ">= 1.2.9"
|
14
|
-
gem.add_dependency 'fastercsv', '>= 1.5.0'
|
15
|
-
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
16
|
-
end
|
17
|
-
Jeweler::GemcutterTasks.new
|
18
|
-
rescue LoadError
|
19
|
-
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
20
|
-
end
|
21
|
-
|
22
|
-
require 'spec/rake/spectask'
|
23
|
-
Spec::Rake::SpecTask.new(:spec) do |spec|
|
24
|
-
spec.libs << 'lib' << 'spec'
|
25
|
-
spec.spec_files = FileList['spec/**/*_spec.rb']
|
26
|
-
end
|
27
|
-
|
28
|
-
Spec::Rake::SpecTask.new(:rcov) do |spec|
|
29
|
-
spec.libs << 'lib' << 'spec'
|
30
|
-
spec.pattern = 'spec/**/*_spec.rb'
|
31
|
-
spec.rcov = true
|
32
|
-
end
|
33
|
-
|
34
|
-
task :spec => :check_dependencies
|
35
|
-
|
36
|
-
task :default => :spec
|
37
|
-
|
38
|
-
require 'rake/rdoctask'
|
39
|
-
Rake::RDocTask.new do |rdoc|
|
40
|
-
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
41
|
-
|
42
|
-
rdoc.rdoc_dir = 'rdoc'
|
43
|
-
rdoc.title = "csv-hash #{version}"
|
44
|
-
rdoc.rdoc_files.include('README*')
|
45
|
-
rdoc.rdoc_files.include('lib/**/*.rb')
|
46
|
-
end
|
1
|
+
require "bundler/gem_tasks"
|
data/csv-hash.gemspec
CHANGED
@@ -1,60 +1,24 @@
|
|
1
|
-
#
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'csv_hash/version'
|
5
5
|
|
6
|
-
Gem::Specification.new do |
|
7
|
-
|
8
|
-
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "csv-hash"
|
8
|
+
spec.version = CSVHash::VERSION
|
9
|
+
spec.authors = ["Tal Atlas"]
|
10
|
+
spec.email = ["me@tal.by"]
|
11
|
+
spec.summary = %q{A gem for interacting with the MTA APIs}
|
12
|
+
spec.description = %q{A gem for interacting with the MTA APIs}
|
13
|
+
spec.homepage = "https://github.com/tal/csv-hash"
|
14
|
+
spec.license = "MIT"
|
9
15
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
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
|
-
]
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
43
20
|
|
44
|
-
|
45
|
-
|
46
|
-
|
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
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.5"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "rspec", "~> 2"
|
59
24
|
end
|
60
|
-
|
data/lib/csv-hash.rb
CHANGED
@@ -1,14 +1,15 @@
|
|
1
|
-
require '
|
1
|
+
require 'csv'
|
2
|
+
|
2
3
|
module CSVHash
|
3
|
-
|
4
|
-
|
4
|
+
extend self
|
5
|
+
|
5
6
|
def from_file file
|
6
7
|
num = 0
|
7
|
-
|
8
|
+
|
8
9
|
data = []
|
9
10
|
columns = []
|
10
|
-
|
11
|
-
|
11
|
+
|
12
|
+
CSV.foreach(file) do |row|
|
12
13
|
num += 1
|
13
14
|
if num == 1
|
14
15
|
columns = row.collect {|c| c.strip if c}
|
@@ -37,10 +38,10 @@ module CSVHash
|
|
37
38
|
|
38
39
|
data << hash
|
39
40
|
end
|
40
|
-
|
41
|
+
|
41
42
|
return data, columns.compact
|
42
43
|
end
|
43
|
-
|
44
|
+
|
44
45
|
def to_string hashes, columns
|
45
46
|
rows = hashes.collect do |hash|
|
46
47
|
vals = columns.collect do |col|
|
@@ -52,12 +53,12 @@ module CSVHash
|
|
52
53
|
end
|
53
54
|
ret
|
54
55
|
end
|
55
|
-
|
56
|
+
|
56
57
|
vals
|
57
58
|
end
|
58
|
-
|
59
|
-
|
60
|
-
csv_string =
|
59
|
+
|
60
|
+
|
61
|
+
csv_string = CSV.generate do |csv|
|
61
62
|
csv << columns
|
62
63
|
rows.each do |val|
|
63
64
|
csv << val
|
@@ -67,6 +68,7 @@ module CSVHash
|
|
67
68
|
end
|
68
69
|
|
69
70
|
# 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
|
71
|
+
# See readme.rdoc for more detaild information
|
70
72
|
def CSVHash arg, columns=nil
|
71
73
|
if arg.is_a?(File)
|
72
74
|
CSVHash.from_file(arg.path)
|
data/lib/csv_hash.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'csv-hash'
|
data/spec/spec_helper.rb
CHANGED
@@ -1,9 +1,20 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
2
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
3
|
+
# Require this file using `require "spec_helper"` to ensure that it is only
|
4
|
+
# loaded once.
|
5
|
+
#
|
6
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
7
|
+
|
3
8
|
require 'csv-hash'
|
4
|
-
require 'spec'
|
5
|
-
require 'spec/autorun'
|
6
9
|
|
7
|
-
|
8
|
-
|
10
|
+
RSpec.configure do |config|
|
11
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
12
|
+
config.run_all_when_everything_filtered = true
|
13
|
+
config.filter_run :focus
|
14
|
+
|
15
|
+
# Run specs in random order to surface order dependencies. If you find an
|
16
|
+
# order dependency and want to debug it, you can fix the order by providing
|
17
|
+
# the seed, which is printed after each run.
|
18
|
+
# --seed 1234
|
19
|
+
config.order = 'random'
|
9
20
|
end
|
metadata
CHANGED
@@ -1,103 +1,104 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: csv-hash
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
segments:
|
6
|
-
- 0
|
7
|
-
- 1
|
8
|
-
- 2
|
9
|
-
version: 0.1.2
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.3
|
10
5
|
platform: ruby
|
11
|
-
authors:
|
6
|
+
authors:
|
12
7
|
- Tal Atlas
|
13
8
|
autorequire:
|
14
9
|
bindir: bin
|
15
10
|
cert_chain: []
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
11
|
+
date: 2014-03-21 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.5'
|
20
|
+
type: :development
|
22
21
|
prerelease: false
|
23
|
-
|
24
|
-
requirements:
|
25
|
-
- -
|
26
|
-
- !ruby/object:Gem::Version
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.5'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '2'
|
32
48
|
type: :development
|
33
|
-
version_requirements: *id001
|
34
|
-
- !ruby/object:Gem::Dependency
|
35
|
-
name: fastercsv
|
36
49
|
prerelease: false
|
37
|
-
|
38
|
-
requirements:
|
39
|
-
- -
|
40
|
-
- !ruby/object:Gem::Version
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
version: 1.5.0
|
46
|
-
type: :runtime
|
47
|
-
version_requirements: *id002
|
48
|
-
description: Will import a CSV as an array of hashes. Or will export a CSV from an array of hashes (if given a column list).
|
49
|
-
email: me@talatlas.com
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '2'
|
55
|
+
description: A gem for interacting with the MTA APIs
|
56
|
+
email:
|
57
|
+
- me@tal.by
|
50
58
|
executables: []
|
51
|
-
|
52
59
|
extensions: []
|
53
|
-
|
54
|
-
|
55
|
-
- LICENSE
|
56
|
-
- README.rdoc
|
57
|
-
files:
|
58
|
-
- .document
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
59
62
|
- .gitignore
|
60
63
|
- LICENSE
|
61
64
|
- README.rdoc
|
62
65
|
- Rakefile
|
63
|
-
- VERSION
|
64
66
|
- csv-hash.gemspec
|
65
67
|
- lib/csv-hash.rb
|
68
|
+
- lib/csv_hash.rb
|
69
|
+
- lib/csv_hash/version.rb
|
66
70
|
- spec/assets/clean_test.csv
|
67
71
|
- spec/assets/test.csv
|
68
72
|
- spec/csv-hash_spec.rb
|
69
73
|
- spec/spec.opts
|
70
74
|
- spec/spec_helper.rb
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
+
homepage: https://github.com/tal/csv-hash
|
76
|
+
licenses:
|
77
|
+
- MIT
|
78
|
+
metadata: {}
|
75
79
|
post_install_message:
|
76
|
-
rdoc_options:
|
77
|
-
|
78
|
-
require_paths:
|
80
|
+
rdoc_options: []
|
81
|
+
require_paths:
|
79
82
|
- lib
|
80
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
81
|
-
requirements:
|
82
|
-
- -
|
83
|
-
- !ruby/object:Gem::Version
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
- !ruby/object:Gem::Version
|
91
|
-
segments:
|
92
|
-
- 0
|
93
|
-
version: "0"
|
83
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - '>='
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
89
|
+
requirements:
|
90
|
+
- - '>='
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: '0'
|
94
93
|
requirements: []
|
95
|
-
|
96
94
|
rubyforge_project:
|
97
|
-
rubygems_version:
|
95
|
+
rubygems_version: 2.0.3
|
98
96
|
signing_key:
|
99
|
-
specification_version:
|
100
|
-
summary: A gem for interacting with
|
101
|
-
test_files:
|
97
|
+
specification_version: 4
|
98
|
+
summary: A gem for interacting with the MTA APIs
|
99
|
+
test_files:
|
100
|
+
- spec/assets/clean_test.csv
|
101
|
+
- spec/assets/test.csv
|
102
102
|
- spec/csv-hash_spec.rb
|
103
|
+
- spec/spec.opts
|
103
104
|
- spec/spec_helper.rb
|
data/.document
DELETED
data/VERSION
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
0.1.2
|