Sha256: 8ddd54e5bf321615bb234c919ff7a4501435d59899fd7cad14c9f47bef2ead1a

Contents?: true

Size: 989 Bytes

Versions: 6

Compression:

Stored size: 989 Bytes

Contents

module Fluent
  class TextParser
    class KVPairParser < Parser
      Plugin.register_parser('kv_pair', self)

      # key<delim1>value is pair and <pair><delim2><pair> ...
      # newline splits records
      include Configurable

      config_param :delim1, :string
      config_param :delim2, :string

      config_param :time_key, :string, :default => "time"
      config_param :time_format, :string, :default => nil # time_format is configurable

      def configure(conf)
        super
        @time_parser = TimeParser.new(@time_format)
      end

      def parse(text)
        text.split("\n").each do |line|
          pairs = text.split(@delim2)
          record = {}
          time = nil
          pairs.each do |pair|
            k, v = pair.split(@delim1, 2)
            if k == @time_key
              time = @time_parser.parse(v)
            else
              record[k] = v
            end
          end
          yield time, record
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
fluent-plugin-parser-0.6.1 test/custom_parser.rb
fluent-plugin-multiline-parser-0.1.1 test/custom_parser.rb
fluent-plugin-multiline-parser-0.1.0 test/custom_parser.rb
fluent-plugin-parser-0.6.0 test/custom_parser.rb
fluent-plugin-parser-0.5.0 test/custom_parser.rb
fluent-plugin-parser-0.4.1 test/custom_parser.rb