Class: FluentExt::TextParser::RegexpParser

Inherits:
GenericParser show all
Includes:
Fluent::Configurable
Defined in:
lib/fluent/plugin/fixed_parser.rb

Instance Attribute Summary

Attributes inherited from GenericParser

#log

Instance Method Summary collapse

Methods inherited from GenericParser

#parse_time

Constructor Details

#initialize(regexp, conf = {}) ⇒ RegexpParser

Returns a new instance of RegexpParser.



66
67
68
69
70
71
72
# File 'lib/fluent/plugin/fixed_parser.rb', line 66

def initialize(regexp, conf={})
  super()
  @regexp = regexp
  unless conf.empty?
    configure(conf)
  end
end

Instance Method Details

#call(text) ⇒ Object



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/fluent/plugin/fixed_parser.rb', line 74

def call(text)
  m = @regexp.match(text)
  unless m
    unless @suppress_parse_error_log
      @log.warn "pattern not match: #{text}"
    end

    return nil, nil
  end

  record = {}
  m.names.each {|name|
    record[name] = m[name] if m[name]
  }
  parse_time(record)
end