Class: HammerCLI::CSVParser

Inherits:
Object
  • Object
show all
Defined in:
lib/hammer_cli/csv_parser.rb

Instance Method Summary collapse

Constructor Details

#initializeCSVParser

Returns a new instance of CSVParser.



4
5
6
# File 'lib/hammer_cli/csv_parser.rb', line 4

def initialize
  reset_parser
end

Instance Method Details

#parse(data) ⇒ Object

Raises:

  • (ArgumentError)


8
9
10
11
12
13
14
15
16
17
# File 'lib/hammer_cli/csv_parser.rb', line 8

def parse(data)
  return [] if data.nil?
  reset_parser
  data.each_char do |char|
    handle_escape(char) || handle_quoting(char) || handle_comma(char) || add_to_buffer(char)
  end
  raise ArgumentError.new(_("Illegal quoting in %{buffer}") % { :buffer => @raw_buffer }) unless @last_quote.nil?
  clean_buffer
  @value
end