Class: Fluent::Plugin::ParserStaticFileCsv

Inherits:
Parser
  • Object
show all
Defined in:
lib/fluent/plugin/parser_static_file_csv.rb

Overview

Fluentd Parser for CSV Text

responsible for parsing CSV content as a whole text

Instance Method Summary collapse

Instance Method Details

#configure(conf) ⇒ Object



21
22
23
24
25
26
# File 'lib/fluent/plugin/parser_static_file_csv.rb', line 21

def configure(conf)
  super

  @parse_options = { col_sep: @delimiter,
                     headers: @has_header }
end

#parse(text) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/fluent/plugin/parser_static_file_csv.rb', line 28

def parse(text)
  csv_content = CSV.parse(text, **@parse_options)
  csv_content.each do |row|
    r = if @has_header && row.respond_to?(:to_h)
          row.to_h
        else
          row_headers = @keys
          row_headers = (1..row.size) if row_headers.empty?

          row_headers.zip(row).to_h
        end

    time, record = convert_values(parse_time(r), r)
    yield time, record
  end
end