Class: CSV::Parser
- Inherits:
-
Object
show all
- Defined in:
- lib/csv/parser.rb
Overview
Note: Don’t use this class directly. This is an internal class.
Defined Under Namespace
Classes: InputsScanner, InvalidEncoding, Scanner, UnoptimizedStringIO
Instance Method Summary
collapse
Constructor Details
#initialize(input, options) ⇒ Parser
Returns a new instance of Parser.
260
261
262
263
264
265
266
|
# File 'lib/csv/parser.rb', line 260
def initialize(input, options)
@input = input
@options = options
@samples = []
prepare
end
|
Instance Method Details
#column_separator ⇒ Object
268
269
270
|
# File 'lib/csv/parser.rb', line 268
def column_separator
@column_separator
end
|
#field_size_limit ⇒ Object
280
281
282
|
# File 'lib/csv/parser.rb', line 280
def field_size_limit
@field_size_limit
end
|
296
297
298
|
# File 'lib/csv/parser.rb', line 296
def
@use_headers and @headers.nil?
end
|
292
293
294
|
# File 'lib/csv/parser.rb', line 292
def
@headers
end
|
#liberal_parsing? ⇒ Boolean
308
309
310
|
# File 'lib/csv/parser.rb', line 308
def liberal_parsing?
@liberal_parsing
end
|
#line ⇒ Object
316
317
318
|
# File 'lib/csv/parser.rb', line 316
def line
last_line
end
|
#lineno ⇒ Object
312
313
314
|
# File 'lib/csv/parser.rb', line 312
def lineno
@lineno
end
|
#parse(&block) ⇒ Object
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
|
# File 'lib/csv/parser.rb', line 320
def parse(&block)
return to_enum(__method__) unless block_given?
if @return_headers and @headers and @raw_headers
= Row.new(@headers, @raw_headers, true)
if @unconverted_fields
= add_unconverted_fields(, [])
end
yield
end
begin
@scanner ||= build_scanner
if quote_character.nil?
parse_no_quote(&block)
elsif @need_robust_parsing
parse_quotable_robust(&block)
else
parse_quotable_loose(&block)
end
rescue InvalidEncoding
if @scanner
ignore_broken_line
lineno = @lineno
else
lineno = @lineno + 1
end
message = "Invalid byte sequence in #{@encoding}"
raise MalformedCSVError.new(message, lineno)
end
end
|
#quote_character ⇒ Object
276
277
278
|
# File 'lib/csv/parser.rb', line 276
def quote_character
@quote_character
end
|
300
301
302
|
# File 'lib/csv/parser.rb', line 300
def
@return_headers
end
|
#row_separator ⇒ Object
272
273
274
|
# File 'lib/csv/parser.rb', line 272
def row_separator
@row_separator
end
|
#skip_blanks? ⇒ Boolean
304
305
306
|
# File 'lib/csv/parser.rb', line 304
def skip_blanks?
@skip_blanks
end
|
#skip_lines ⇒ Object
284
285
286
|
# File 'lib/csv/parser.rb', line 284
def skip_lines
@skip_lines
end
|
#unconverted_fields? ⇒ Boolean
288
289
290
|
# File 'lib/csv/parser.rb', line 288
def unconverted_fields?
@unconverted_fields
end
|
352
353
354
|
# File 'lib/csv/parser.rb', line 352
def
@use_headers
end
|