Class: CSV::Parser
- Inherits:
-
Object
show all
- Defined in:
- lib/csv/parser.rb
Defined Under Namespace
Classes: InputsScanner, InvalidEncoding, Scanner, UnoptimizedStringIO
Instance Method Summary
collapse
Constructor Details
#initialize(input, options) ⇒ Parser
Returns a new instance of Parser.
225
226
227
228
229
230
231
|
# File 'lib/csv/parser.rb', line 225
def initialize(input, options)
@input = input
@options = options
@samples = []
prepare
end
|
Instance Method Details
#column_separator ⇒ Object
233
234
235
|
# File 'lib/csv/parser.rb', line 233
def column_separator
@column_separator
end
|
#field_size_limit ⇒ Object
245
246
247
|
# File 'lib/csv/parser.rb', line 245
def field_size_limit
@field_size_limit
end
|
261
262
263
|
# File 'lib/csv/parser.rb', line 261
def
@use_headers and @headers.nil?
end
|
257
258
259
|
# File 'lib/csv/parser.rb', line 257
def
@headers
end
|
#liberal_parsing? ⇒ Boolean
273
274
275
|
# File 'lib/csv/parser.rb', line 273
def liberal_parsing?
@liberal_parsing
end
|
#line ⇒ Object
281
282
283
|
# File 'lib/csv/parser.rb', line 281
def line
last_line
end
|
#lineno ⇒ Object
277
278
279
|
# File 'lib/csv/parser.rb', line 277
def lineno
@lineno
end
|
#parse(&block) ⇒ Object
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
|
# File 'lib/csv/parser.rb', line 285
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
241
242
243
|
# File 'lib/csv/parser.rb', line 241
def quote_character
@quote_character
end
|
265
266
267
|
# File 'lib/csv/parser.rb', line 265
def
@return_headers
end
|
#row_separator ⇒ Object
237
238
239
|
# File 'lib/csv/parser.rb', line 237
def row_separator
@row_separator
end
|
#skip_blanks? ⇒ Boolean
269
270
271
|
# File 'lib/csv/parser.rb', line 269
def skip_blanks?
@skip_blanks
end
|
#skip_lines ⇒ Object
249
250
251
|
# File 'lib/csv/parser.rb', line 249
def skip_lines
@skip_lines
end
|
#unconverted_fields? ⇒ Boolean
253
254
255
|
# File 'lib/csv/parser.rb', line 253
def unconverted_fields?
@unconverted_fields
end
|
317
318
319
|
# File 'lib/csv/parser.rb', line 317
def
@use_headers
end
|