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.
191
192
193
194
195
196
197
|
# File 'lib/csv/parser.rb', line 191
def initialize(input, options)
@input = input
@options = options
@samples = []
prepare
end
|
Instance Method Details
#column_separator ⇒ Object
199
200
201
|
# File 'lib/csv/parser.rb', line 199
def column_separator
@column_separator
end
|
#field_size_limit ⇒ Object
211
212
213
|
# File 'lib/csv/parser.rb', line 211
def field_size_limit
@field_size_limit
end
|
227
228
229
|
# File 'lib/csv/parser.rb', line 227
def
@use_headers and @headers.nil?
end
|
223
224
225
|
# File 'lib/csv/parser.rb', line 223
def
@headers
end
|
#liberal_parsing? ⇒ Boolean
239
240
241
|
# File 'lib/csv/parser.rb', line 239
def liberal_parsing?
@liberal_parsing
end
|
#line ⇒ Object
247
248
249
|
# File 'lib/csv/parser.rb', line 247
def line
last_line
end
|
#lineno ⇒ Object
243
244
245
|
# File 'lib/csv/parser.rb', line 243
def lineno
@lineno
end
|
#parse(&block) ⇒ Object
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
|
# File 'lib/csv/parser.rb', line 251
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)
else
parse_quotable(&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
207
208
209
|
# File 'lib/csv/parser.rb', line 207
def quote_character
@quote_character
end
|
231
232
233
|
# File 'lib/csv/parser.rb', line 231
def
@return_headers
end
|
#row_separator ⇒ Object
203
204
205
|
# File 'lib/csv/parser.rb', line 203
def row_separator
@row_separator
end
|
#skip_blanks? ⇒ Boolean
235
236
237
|
# File 'lib/csv/parser.rb', line 235
def skip_blanks?
@skip_blanks
end
|
#skip_lines ⇒ Object
215
216
217
|
# File 'lib/csv/parser.rb', line 215
def skip_lines
@skip_lines
end
|
#unconverted_fields? ⇒ Boolean
219
220
221
|
# File 'lib/csv/parser.rb', line 219
def unconverted_fields?
@unconverted_fields
end
|
281
282
283
|
# File 'lib/csv/parser.rb', line 281
def
@use_headers
end
|