fasterer-csv 0.0.14 → 1.0.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/.document +4 -0
- data/.gitignore +10 -0
- data/LICENSE +3 -0
- data/README.rdoc +26 -0
- data/Rakefile +42 -0
- data/VERSION +1 -0
- data/fasterer-csv.gemspec +69 -0
- data/lib/fasterer_csv.rb +43 -17
- data/pkg/fasterer-csv-0.0.1.gem +0 -0
- data/pkg/fasterer-csv-0.0.10.gem +0 -0
- data/pkg/fasterer-csv-0.0.11.gem +0 -0
- data/pkg/fasterer-csv-0.0.12.gem +0 -0
- data/pkg/fasterer-csv-0.0.14.gem +0 -0
- data/pkg/fasterer-csv-0.0.2.gem +0 -0
- data/pkg/fasterer-csv-0.0.3.gem +0 -0
- data/pkg/fasterer-csv-0.0.4.gem +0 -0
- data/pkg/fasterer-csv-0.0.5.gem +0 -0
- data/pkg/fasterer-csv-0.0.6.gem +0 -0
- data/pkg/fasterer-csv-0.0.7.gem +0 -0
- data/pkg/fasterer-csv-0.0.8.gem +0 -0
- data/pkg/fasterer-csv-0.0.9.gem +0 -0
- data/pkg/fasterer-csv-1.0.0.gem +0 -0
- data/spec/fasterer_csv_spec.rb +161 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +9 -0
- metadata +39 -11
- data/README +0 -0
data/.document
ADDED
data/.gitignore
ADDED
data/LICENSE
ADDED
data/README.rdoc
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
= fasterer-csv
|
2
|
+
|
3
|
+
Normal FasterCSV was just too slow for the project I was working on taking a billion trallion years to read in these tons of huge CSV files, so: this.
|
4
|
+
|
5
|
+
Depends on various stuff and such it almost always reads at least twice as fast, sometimes up to 40x as fast.
|
6
|
+
|
7
|
+
It's got some caveats, though... which you'll discover in fun and entertaining ways.
|
8
|
+
|
9
|
+
Also, it's not *completely* a drop in replacement, but it's really really close. Why do it this way? Because I hate you and want to make you life a little more difficult whenever possible.
|
10
|
+
|
11
|
+
|
12
|
+
== Note on Patches/Pull Requests
|
13
|
+
|
14
|
+
* Spoon the project.
|
15
|
+
* Make your feature addition or bug fix.
|
16
|
+
* Add tests for it. This is important so I don't break it in a
|
17
|
+
future version unintentionally.
|
18
|
+
* Commit, do not mess with rakefile, version, or history.
|
19
|
+
(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)
|
20
|
+
* Send me a pull request.
|
21
|
+
* Delete everything you've done at the point because I'm probably going to reimplement it anyways.
|
22
|
+
|
23
|
+
== Monkyright
|
24
|
+
|
25
|
+
Monkeyright (m) 2010 Mason. See LICENSE for details.
|
26
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
|
8
|
+
gem.name = %q{fasterer-csv}
|
9
|
+
gem.authors = ["Mason"]
|
10
|
+
gem.email = %q{mason@chipped.net}
|
11
|
+
gem.date = Time.now.strftime("%Y-%m-%d")
|
12
|
+
gem.description = %q{CSV parsing awesomeness}
|
13
|
+
gem.summary = %q{Even fasterer than FasterCSV!}
|
14
|
+
gem.homepage = %q{http://github.com/gnovos/fasterer-csv}
|
15
|
+
gem.post_install_message = <<-POST
|
16
|
+
Kernel Panic! System32 deleted! Klaxons klaxoning! Dogs and Cats living together!!!! We're doooomed! Everything is...
|
17
|
+
oh, no wait, it installed fine. My bad.
|
18
|
+
POST
|
19
|
+
|
20
|
+
end
|
21
|
+
Jeweler::GemcutterTasks.new
|
22
|
+
rescue LoadError
|
23
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler you doof"
|
24
|
+
end
|
25
|
+
|
26
|
+
require 'spec/rake/spectask'
|
27
|
+
Spec::Rake::SpecTask.new(:spec) do |spec|
|
28
|
+
spec.libs << 'lib' << 'spec'
|
29
|
+
spec.spec_files = FileList['spec/**/*_spec.rb']
|
30
|
+
end
|
31
|
+
|
32
|
+
task :default => :spec
|
33
|
+
|
34
|
+
require 'rake/rdoctask'
|
35
|
+
Rake::RDocTask.new do |rdoc|
|
36
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
37
|
+
|
38
|
+
rdoc.rdoc_dir = 'rdoc'
|
39
|
+
rdoc.title = "FastererCSV #{version}"
|
40
|
+
rdoc.rdoc_files.include('README*')
|
41
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
42
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
1.0.0
|
@@ -0,0 +1,69 @@
|
|
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{fasterer-csv}
|
8
|
+
s.version = "1.0.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Mason"]
|
12
|
+
s.date = %q{2010-06-17}
|
13
|
+
s.description = %q{CSV parsing awesomeness}
|
14
|
+
s.email = %q{mason@chipped.net}
|
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
|
+
"fasterer-csv.gemspec",
|
27
|
+
"lib/fasterer_csv.rb",
|
28
|
+
"pkg/fasterer-csv-0.0.1.gem",
|
29
|
+
"pkg/fasterer-csv-0.0.10.gem",
|
30
|
+
"pkg/fasterer-csv-0.0.11.gem",
|
31
|
+
"pkg/fasterer-csv-0.0.12.gem",
|
32
|
+
"pkg/fasterer-csv-0.0.14.gem",
|
33
|
+
"pkg/fasterer-csv-0.0.2.gem",
|
34
|
+
"pkg/fasterer-csv-0.0.3.gem",
|
35
|
+
"pkg/fasterer-csv-0.0.4.gem",
|
36
|
+
"pkg/fasterer-csv-0.0.5.gem",
|
37
|
+
"pkg/fasterer-csv-0.0.6.gem",
|
38
|
+
"pkg/fasterer-csv-0.0.7.gem",
|
39
|
+
"pkg/fasterer-csv-0.0.8.gem",
|
40
|
+
"pkg/fasterer-csv-0.0.9.gem",
|
41
|
+
"pkg/fasterer-csv-1.0.0.gem",
|
42
|
+
"spec/fasterer_csv_spec.rb",
|
43
|
+
"spec/spec.opts",
|
44
|
+
"spec/spec_helper.rb"
|
45
|
+
]
|
46
|
+
s.homepage = %q{http://github.com/gnovos/fasterer-csv}
|
47
|
+
s.post_install_message = %q{Kernel Panic! System32 deleted! Klaxons klaxoning! Dogs and Cats living together!!!! We're doooomed! Everything is...
|
48
|
+
oh, no wait, it installed fine. My bad.
|
49
|
+
}
|
50
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
51
|
+
s.require_paths = ["lib"]
|
52
|
+
s.rubygems_version = %q{1.3.7}
|
53
|
+
s.summary = %q{Even fasterer than FasterCSV!}
|
54
|
+
s.test_files = [
|
55
|
+
"spec/fasterer_csv_spec.rb",
|
56
|
+
"spec/spec_helper.rb"
|
57
|
+
]
|
58
|
+
|
59
|
+
if s.respond_to? :specification_version then
|
60
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
61
|
+
s.specification_version = 3
|
62
|
+
|
63
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
64
|
+
else
|
65
|
+
end
|
66
|
+
else
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
data/lib/fasterer_csv.rb
CHANGED
@@ -106,6 +106,9 @@ module FastererCSV
|
|
106
106
|
end
|
107
107
|
end
|
108
108
|
end
|
109
|
+
|
110
|
+
alias_method :rows, :to_a
|
111
|
+
|
109
112
|
end
|
110
113
|
|
111
114
|
class Row < Array
|
@@ -153,13 +156,13 @@ module FastererCSV
|
|
153
156
|
end
|
154
157
|
end
|
155
158
|
|
156
|
-
def
|
157
|
-
columns.map do |
|
158
|
-
self[
|
159
|
+
def pull(*columns)
|
160
|
+
columns.map do |column|
|
161
|
+
self[*column]
|
159
162
|
end
|
160
163
|
end
|
161
164
|
|
162
|
-
def merge(row)
|
165
|
+
def merge!(row)
|
163
166
|
if row.is_a? Row
|
164
167
|
row.headers.each do |header|
|
165
168
|
self[header] = row[header]
|
@@ -178,6 +181,28 @@ module FastererCSV
|
|
178
181
|
memo
|
179
182
|
end
|
180
183
|
end
|
184
|
+
|
185
|
+
def key?(key)
|
186
|
+
keys.include?(Row.to_key(key))
|
187
|
+
end
|
188
|
+
|
189
|
+
def value?(value)
|
190
|
+
values.include?(value)
|
191
|
+
end
|
192
|
+
|
193
|
+
def method_missing(method, *args, &block)
|
194
|
+
to_hash.send(method, *args, &block)
|
195
|
+
end
|
196
|
+
|
197
|
+
alias_method :keys, :headers
|
198
|
+
alias_method :values, :to_a
|
199
|
+
|
200
|
+
alias_method :has_key?, :key?
|
201
|
+
alias_method :member?, :key?
|
202
|
+
alias_method :include?, :key?
|
203
|
+
|
204
|
+
alias_method :has_value?, :value?
|
205
|
+
|
181
206
|
end
|
182
207
|
|
183
208
|
class NumericConversion < Array
|
@@ -242,6 +267,19 @@ module FastererCSV
|
|
242
267
|
|
243
268
|
end
|
244
269
|
|
270
|
+
class IOWriter
|
271
|
+
def initialize(file, quot = '~', sep = ',') @first = true; @io = file; @quot = quot; @sep = sep end
|
272
|
+
def <<(row)
|
273
|
+
raise "can only write arrays! #{row.class} #{row.inspect}" unless row.is_a? Array
|
274
|
+
if @first && row.is_a?(Row)
|
275
|
+
@first = false
|
276
|
+
self.<<(row.headers)
|
277
|
+
end
|
278
|
+
@io.syswrite FastererCSV::quot_row(row, @quot, @sep)
|
279
|
+
row
|
280
|
+
end
|
281
|
+
end
|
282
|
+
|
245
283
|
class << self
|
246
284
|
|
247
285
|
def headers(file, quot = '~', sep = ',', fail_on_malformed = true, column = NoConversion.new, &block)
|
@@ -352,19 +390,6 @@ module FastererCSV
|
|
352
390
|
end.join(s) + "\n"
|
353
391
|
end
|
354
392
|
|
355
|
-
class IOWriter
|
356
|
-
def initialize(file, quot = '~', sep = ',') @first = true; @io = file; @quot = quot; @sep = sep end
|
357
|
-
def <<(row)
|
358
|
-
raise "can only write arrays! #{row.class} #{row.inspect}" unless row.is_a? Array
|
359
|
-
if @first && row.is_a?(Row)
|
360
|
-
@first = false
|
361
|
-
self.<<(row.headers)
|
362
|
-
end
|
363
|
-
@io.syswrite FastererCSV::quot_row(row, @quot, @sep)
|
364
|
-
row
|
365
|
-
end
|
366
|
-
end
|
367
|
-
|
368
393
|
def generate(quot = '~', sep = ',', &block)
|
369
394
|
builder = StringIO.new
|
370
395
|
write(builder, quot, sep, &block)
|
@@ -382,3 +407,4 @@ module FastererCSV
|
|
382
407
|
end
|
383
408
|
end
|
384
409
|
end
|
410
|
+
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
@@ -0,0 +1,161 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe "FastererCSV" do
|
4
|
+
|
5
|
+
describe "fiddly bits" do
|
6
|
+
describe "Table" do
|
7
|
+
it "works" do
|
8
|
+
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "Row" do
|
13
|
+
it "works" do
|
14
|
+
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "Converters" do
|
20
|
+
describe "NumericConverters" do
|
21
|
+
it "works" do
|
22
|
+
|
23
|
+
conv = FastererCSV::NumericConversion.new
|
24
|
+
conv << ?1
|
25
|
+
conv.convert(true).class.should == String
|
26
|
+
conv.convert(true).should == "1"
|
27
|
+
|
28
|
+
conv.convert(false).class.should == Fixnum
|
29
|
+
conv.convert(false).should == 1
|
30
|
+
|
31
|
+
conv.clear
|
32
|
+
conv << ?-
|
33
|
+
conv << ?1
|
34
|
+
conv.convert(false).class.should == Fixnum
|
35
|
+
conv.convert(false).should == -1
|
36
|
+
|
37
|
+
conv.clear
|
38
|
+
conv << ?1
|
39
|
+
conv << ?.
|
40
|
+
conv << ?1
|
41
|
+
conv.convert(false).class.should == Float
|
42
|
+
conv.convert(false).should == 1.1
|
43
|
+
|
44
|
+
conv.clear
|
45
|
+
conv << ?-
|
46
|
+
conv << ?1
|
47
|
+
conv << ?.
|
48
|
+
conv << ?1
|
49
|
+
conv.convert(false).class.should == Float
|
50
|
+
conv.convert(false).should == -1.1
|
51
|
+
|
52
|
+
conv.clear
|
53
|
+
conv << ?1
|
54
|
+
conv << ?.
|
55
|
+
conv << ?1
|
56
|
+
conv << ?.
|
57
|
+
conv << ?1
|
58
|
+
conv.convert(false).class.should == String
|
59
|
+
conv.convert(false).should == "1.1.1"
|
60
|
+
|
61
|
+
conv.clear
|
62
|
+
conv << ?a
|
63
|
+
conv.convert(false).class.should == String
|
64
|
+
conv.convert(false).should == "a"
|
65
|
+
|
66
|
+
conv.clear
|
67
|
+
conv.should be_empty
|
68
|
+
conv.convert(false).should be_nil
|
69
|
+
conv.convert(true).should == ""
|
70
|
+
|
71
|
+
end
|
72
|
+
end
|
73
|
+
describe "NoConverter" do
|
74
|
+
it "works" do
|
75
|
+
|
76
|
+
conv = FastererCSV::NoConversion.new
|
77
|
+
conv << ?1
|
78
|
+
conv.convert(true).class.should == String
|
79
|
+
conv.convert(false).class.should == String
|
80
|
+
|
81
|
+
conv.convert(true).should == "1"
|
82
|
+
conv.convert(false).should == "1"
|
83
|
+
|
84
|
+
conv.clear
|
85
|
+
conv.should be_empty
|
86
|
+
conv.convert(false).should be_nil
|
87
|
+
conv.convert(true).should == ""
|
88
|
+
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
describe "important stuff" do
|
94
|
+
|
95
|
+
before do
|
96
|
+
@data = <<-CSV
|
97
|
+
a,b,c,d,e,f,g,h,i,j,k,l,m,n
|
98
|
+
,,1,1.1,-1,-1.1,1.1.1,~1~,a,~a~,~a~~a~,~a
|
99
|
+
~~a~,~,~,
|
100
|
+
|
101
|
+
0,1,2,3,4,5,6,7,8,9,10,11,12,14
|
102
|
+
CSV
|
103
|
+
end
|
104
|
+
|
105
|
+
describe "parse" do
|
106
|
+
it "works" do
|
107
|
+
table = FastererCSV.parse(@data)
|
108
|
+
table.headers.should == [:a, :b, :c,:d,:e,:f,:g,:h,:i,:j,:k,:l,:m,:n]
|
109
|
+
table.lines.should == 2
|
110
|
+
|
111
|
+
table[0].should == [nil, nil, "1", "1.1", "-1", "-1.1", "1.1.1", "1", "a", "a", "a~a", "a\n~a", ",", nil]
|
112
|
+
table[1].should == ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "14"]
|
113
|
+
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
describe "read" do
|
118
|
+
it "" do
|
119
|
+
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
describe "read_converted" do
|
124
|
+
it "" do
|
125
|
+
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
describe "headers" do
|
130
|
+
it "" do
|
131
|
+
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
describe "parse_headers" do
|
136
|
+
it "" do
|
137
|
+
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
describe "quot_row" do
|
142
|
+
it "" do
|
143
|
+
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
describe "generate" do
|
148
|
+
it "" do
|
149
|
+
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
describe "write" do
|
154
|
+
it "" do
|
155
|
+
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
end
|
160
|
+
|
161
|
+
end
|
data/spec/spec.opts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/spec/spec_helper.rb
ADDED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fasterer-csv
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
|
+
- 1
|
7
8
|
- 0
|
8
9
|
- 0
|
9
|
-
|
10
|
-
version: 0.0.14
|
10
|
+
version: 1.0.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Mason
|
@@ -15,28 +15,55 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-06-
|
18
|
+
date: 2010-06-17 00:00:00 -07:00
|
19
19
|
default_executable:
|
20
20
|
dependencies: []
|
21
21
|
|
22
22
|
description: CSV parsing awesomeness
|
23
|
-
email: mason@
|
23
|
+
email: mason@chipped.net
|
24
24
|
executables: []
|
25
25
|
|
26
26
|
extensions: []
|
27
27
|
|
28
28
|
extra_rdoc_files:
|
29
|
-
-
|
29
|
+
- LICENSE
|
30
|
+
- README.rdoc
|
30
31
|
files:
|
31
|
-
-
|
32
|
+
- .document
|
33
|
+
- .gitignore
|
34
|
+
- LICENSE
|
35
|
+
- README.rdoc
|
36
|
+
- Rakefile
|
37
|
+
- VERSION
|
38
|
+
- fasterer-csv.gemspec
|
32
39
|
- lib/fasterer_csv.rb
|
40
|
+
- pkg/fasterer-csv-0.0.1.gem
|
41
|
+
- pkg/fasterer-csv-0.0.10.gem
|
42
|
+
- pkg/fasterer-csv-0.0.11.gem
|
43
|
+
- pkg/fasterer-csv-0.0.12.gem
|
44
|
+
- pkg/fasterer-csv-0.0.14.gem
|
45
|
+
- pkg/fasterer-csv-0.0.2.gem
|
46
|
+
- pkg/fasterer-csv-0.0.3.gem
|
47
|
+
- pkg/fasterer-csv-0.0.4.gem
|
48
|
+
- pkg/fasterer-csv-0.0.5.gem
|
49
|
+
- pkg/fasterer-csv-0.0.6.gem
|
50
|
+
- pkg/fasterer-csv-0.0.7.gem
|
51
|
+
- pkg/fasterer-csv-0.0.8.gem
|
52
|
+
- pkg/fasterer-csv-0.0.9.gem
|
53
|
+
- pkg/fasterer-csv-1.0.0.gem
|
54
|
+
- spec/fasterer_csv_spec.rb
|
55
|
+
- spec/spec.opts
|
56
|
+
- spec/spec_helper.rb
|
33
57
|
has_rdoc: true
|
34
58
|
homepage: http://github.com/gnovos/fasterer-csv
|
35
59
|
licenses: []
|
36
60
|
|
37
|
-
post_install_message:
|
38
|
-
|
61
|
+
post_install_message: |
|
62
|
+
Kernel Panic! System32 deleted! Klaxons klaxoning! Dogs and Cats living together!!!! We're doooomed! Everything is...
|
63
|
+
oh, no wait, it installed fine. My bad.
|
39
64
|
|
65
|
+
rdoc_options:
|
66
|
+
- --charset=UTF-8
|
40
67
|
require_paths:
|
41
68
|
- lib
|
42
69
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -64,5 +91,6 @@ rubygems_version: 1.3.7
|
|
64
91
|
signing_key:
|
65
92
|
specification_version: 3
|
66
93
|
summary: Even fasterer than FasterCSV!
|
67
|
-
test_files:
|
68
|
-
|
94
|
+
test_files:
|
95
|
+
- spec/fasterer_csv_spec.rb
|
96
|
+
- spec/spec_helper.rb
|
data/README
DELETED
File without changes
|