Parent

Methods

Class/Module Index [+]

Quicksearch

Fluent::TextParser::TimeParser

Public Class Methods

new(time_format) click to toggle source
# File lib/fluent/parser.rb, line 23
def initialize(time_format)
  @cache1_key = nil
  @cache1_time = nil
  @cache2_key = nil
  @cache2_time = nil
  @parser =
    if time_format
      Proc.new { |value| Time.strptime(value, time_format) }
    else
      Time.method(:parse)
    end
end

Public Instance Methods

parse(value) click to toggle source
# File lib/fluent/parser.rb, line 36
def parse(value)
  unless value.is_a?(String)
    raise ArgumentError, "Value must be string: #{value}"
  end

  if @cache1_key == value
    return @cache1_time
  elsif @cache2_key == value
    return @cache2_time
  else
    time = @parser.call(value).to_i
    @cache1_key = @cache2_key
    @cache1_time = @cache2_time
    @cache2_key = value
    @cache2_time = time
    return time
  end
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.