class Fluent::TextParser::RegexpParser

Public Class Methods

new(regexp, conf={}) click to toggle source
Calls superclass method Fluent::Parser.new
# File lib/fluent/parser.rb, line 165
def initialize(regexp, conf={})
  super()
  @regexp = regexp
  unless conf.empty?
    configure(conf)
  end

  @time_parser = TimeParser.new(@time_format)
  @mutex = Mutex.new
end

Public Instance Methods

configure(conf) click to toggle source
# File lib/fluent/parser.rb, line 176
def configure(conf)
  super
  @time_parser = TimeParser.new(@time_format)
end
parse(text) { |nil, nil| ... } click to toggle source
# File lib/fluent/parser.rb, line 185
def parse(text)
  m = @regexp.match(text)
  unless m
    if block_given?
      yield nil, nil
      return
    else
      return nil, nil
    end
  end

  time = nil
  record = {}

  m.names.each {|name|
    if value = m[name]
      case name
      when "time"
        time = @mutex.synchronize { @time_parser.parse(value) }
      else
        record[name] = if @type_converters.nil?
                         value
                       else
                         convert_type(name, value)
                       end
      end
    end
  }

  if @estimate_current_event
    time ||= Engine.now
  end

  if block_given?
    yield time, record
  else # keep backward compatibility. will be removed at v1
    return time, record
  end
end
patterns() click to toggle source
# File lib/fluent/parser.rb, line 181
def patterns
  {'format' => @regexp, 'time_format' => @time_format}
end