Parent

Class/Module Index [+]

Quicksearch

Fluent::TextParser

Constants

TEMPLATE_FACTORIES

Public Class Methods

new() click to toggle source
# File lib/fluent/parser.rb, line 247
def initialize
  @parser = nil
end
register_template(name, regexp_or_proc, time_format=nil) click to toggle source
# File lib/fluent/parser.rb, line 236
def self.register_template(name, regexp_or_proc, time_format=nil)
  if regexp_or_proc.is_a?(Regexp)
    regexp = regexp_or_proc
    factory = Proc.new { RegexpParser.new(regexp, {'time_format'=>time_format}) }
  else
    factory = regexp_or_proc
  end

  TEMPLATE_FACTORIES[name] = factory
end

Public Instance Methods

configure(conf, required=true) click to toggle source
# File lib/fluent/parser.rb, line 251
def configure(conf, required=true)
  format = conf['format']

  if format == nil
    if required
      raise ConfigError, "'format' parameter is required"
    else
      return nil
    end
  end

  if format[0] == // && format[format.length-1] == //
    # regexp
    begin
      regexp = Regexp.new(format[1..-2])
      if regexp.named_captures.empty?
        raise "No named captures"
      end
    rescue
      raise ConfigError, "Invalid regexp '#{format[1..-2]}': #{$!}"
    end

    @parser = RegexpParser.new(regexp)

  else
    # built-in template
    factory = TEMPLATE_FACTORIES[format]
    unless factory
      raise ConfigError, "Unknown format template '#{format}'"
    end
    @parser = factory.call
  end

  if @parser.respond_to?(:configure)
    @parser.configure(conf)
  end

  return true
end
parse(text) click to toggle source
# File lib/fluent/parser.rb, line 291
def parse(text)
  return @parser.call(text)
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.