Class: Fluent::TextParser::ValuesParser

Inherits:
Object
  • Object
show all
Includes:
Configurable
Defined in:
lib/fluent/parser.rb

Direct Known Subclasses

CSVParser, LabeledTSVParser, TSVParser

Instance Attribute Summary

Attributes included from Configurable

#config

Instance Method Summary collapse

Methods included from Configurable

included, #initialize

Instance Method Details

#configure(conf) ⇒ Object



99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/fluent/parser.rb', line 99

def configure(conf)
  super

  @keys = @keys.split(",")

  if @time_key && !@keys.include?(@time_key)
    raise ConfigError, "time_key (#{@time_key.inspect}) is not included in keys (#{@keys.inspect})"
  end

  if @time_format && !@time_key
    $log.warn "time_format parameter is ignored because time_key parameter is not set"
  end
end

#values_map(values) ⇒ Object



113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/fluent/parser.rb', line 113

def values_map(values)
  record = Hash[keys.zip(values)]

  if @time_key
    value = record[@time_key]
    if @time_format
      time = Time.strptime(value, @time_format).to_i
    else
      time = Time.parse(value).to_i
    end
  else
    time = Engine.now
  end

  return time, record
end