fasterer-csv 0.0.8 → 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/fasterer_csv.rb +17 -15
- metadata +4 -4
data/lib/fasterer_csv.rb
CHANGED
@@ -182,28 +182,26 @@ module FastererCSV
|
|
182
182
|
end
|
183
183
|
end
|
184
184
|
|
185
|
-
class
|
185
|
+
class NumericConversion < Array
|
186
186
|
|
187
187
|
def initialize
|
188
|
-
@int = true
|
189
|
-
@float = true
|
188
|
+
@int = @float = true
|
190
189
|
@dot = false
|
191
190
|
end
|
192
191
|
|
193
192
|
def clear
|
194
|
-
@int = true
|
195
|
-
@float = true
|
193
|
+
@int = @float = true
|
196
194
|
@dot = false
|
197
195
|
super
|
198
196
|
end
|
199
197
|
|
200
198
|
def <<(ch)
|
201
|
-
if
|
202
|
-
@int =
|
203
|
-
|
199
|
+
if ch == ?-
|
200
|
+
@float = @int = size == 0
|
201
|
+
elsif (ch > ?9 || ch < ?0) && ch != ?.
|
202
|
+
@int = @float = false
|
204
203
|
elsif ch == ?. && @dot
|
205
|
-
@int = false
|
206
|
-
@float = false
|
204
|
+
@int = @float = false
|
207
205
|
elsif ch == ?.
|
208
206
|
@int = false
|
209
207
|
@dot = true
|
@@ -224,7 +222,7 @@ module FastererCSV
|
|
224
222
|
|
225
223
|
end
|
226
224
|
|
227
|
-
class
|
225
|
+
class NoConversion < Array
|
228
226
|
|
229
227
|
def <<(ch)
|
230
228
|
super(ch.chr)
|
@@ -234,19 +232,23 @@ module FastererCSV
|
|
234
232
|
|
235
233
|
class << self
|
236
234
|
|
237
|
-
def headers(file, quot = '~', sep = ',', fail_on_malformed = true, column =
|
235
|
+
def headers(file, quot = '~', sep = ',', fail_on_malformed = true, column = NumericConversion.new, &block)
|
238
236
|
parse_headers(File.open(file, 'r') {|io| io.gets }, quot, sep, fail_on_malformed, column, &block)
|
239
237
|
end
|
240
238
|
|
241
|
-
def read(file, quot = '~', sep = ',', fail_on_malformed = true, column =
|
239
|
+
def read(file, quot = '~', sep = ',', fail_on_malformed = true, column = NumericConversion.new, &block)
|
240
|
+
parse(File.open(file, 'r') { |io| io.sysread(File.size(file)) }, quot, sep, fail_on_malformed, column, &block)
|
241
|
+
end
|
242
|
+
|
243
|
+
def read_plain(file, quot = '~', sep = ',', fail_on_malformed = true, column = NoConversion.new, &block)
|
242
244
|
parse(File.open(file, 'r') { |io| io.sysread(File.size(file)) }, quot, sep, fail_on_malformed, column, &block)
|
243
245
|
end
|
244
246
|
|
245
|
-
def parse_headers(data, quot = '~', sep = ',', fail_on_malformed = true, column =
|
247
|
+
def parse_headers(data, quot = '~', sep = ',', fail_on_malformed = true, column = NumericConversion.new, &block)
|
246
248
|
parse(data, quot, sep, fail_on_malformed, column, &block).headers
|
247
249
|
end
|
248
250
|
|
249
|
-
def parse(data, quot = '~', sep = ',', fail_on_malformed = true, column =
|
251
|
+
def parse(data, quot = '~', sep = ',', fail_on_malformed = true, column = NumericConversion.new)
|
250
252
|
q, s, row, inquot, clean, maybe, table, field, endline = quot[0], sep[0], [], false, true, false, nil, true, false
|
251
253
|
|
252
254
|
data.each_byte do |c|
|
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: 13
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 9
|
10
|
+
version: 0.0.9
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Mason
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-06-
|
18
|
+
date: 2010-06-16 00:00:00 -07:00
|
19
19
|
default_executable:
|
20
20
|
dependencies: []
|
21
21
|
|