csv-hash 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -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
@@ -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 'rubygems'
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"
@@ -1,60 +1,24 @@
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 -*-
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 |s|
7
- s.name = %q{csv-hash}
8
- s.version = "0.1.2"
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
- 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
- ]
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
- 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
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
-
@@ -1,14 +1,15 @@
1
- require 'faster_csv'
1
+ require 'csv'
2
+
2
3
  module CSVHash
3
- module_function
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
- FasterCSV.foreach(file) do |row|
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 = FasterCSV.generate do |csv|
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)
@@ -0,0 +1 @@
1
+ require 'csv-hash'
@@ -0,0 +1,3 @@
1
+ module CSVHash
2
+ VERSION="0.1.3"
3
+ end
@@ -1,9 +1,20 @@
1
- $LOAD_PATH.unshift(File.dirname(__FILE__))
2
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
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
- Spec::Runner.configure do |config|
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
- prerelease: false
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
- date: 2010-05-26 00:00:00 -04:00
18
- default_executable:
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
21
- name: rspec
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
- requirement: &id001 !ruby/object:Gem::Requirement
24
- requirements:
25
- - - ">="
26
- - !ruby/object:Gem::Version
27
- segments:
28
- - 1
29
- - 2
30
- - 9
31
- version: 1.2.9
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
- requirement: &id002 !ruby/object:Gem::Requirement
38
- requirements:
39
- - - ">="
40
- - !ruby/object:Gem::Version
41
- segments:
42
- - 1
43
- - 5
44
- - 0
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
- extra_rdoc_files:
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
- has_rdoc: true
72
- homepage: http://github.com/Talby/csv-hash
73
- licenses: []
74
-
75
+ homepage: https://github.com/tal/csv-hash
76
+ licenses:
77
+ - MIT
78
+ metadata: {}
75
79
  post_install_message:
76
- rdoc_options:
77
- - --charset=UTF-8
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
- segments:
85
- - 0
86
- version: "0"
87
- required_rubygems_version: !ruby/object:Gem::Requirement
88
- requirements:
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: 1.3.6
95
+ rubygems_version: 2.0.3
98
96
  signing_key:
99
- specification_version: 3
100
- summary: A gem for interacting with CSVs as hashes
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
@@ -1,5 +0,0 @@
1
- README.rdoc
2
- lib/**/*.rb
3
- bin/*
4
- features/**/*.feature
5
- LICENSE
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 0.1.2