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 54
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 67
def parse(value)
  unless value.is_a?(String)
    raise ParserError, "value must be string: #{value}"
  end

  if @cache1_key == value
    return @cache1_time
  elsif @cache2_key == value
    return @cache2_time
  else
    begin
      time = @parser.call(value).to_i
    rescue => e
      raise ParserError, "invalid time format: value = #{value}, error_class = #{e.class.name}, error = #{e.message}"
    end
    @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.