class Fluent::Plugin::NfctParser

Constants

DELIMITER
LABEL_SCAN
NUM_REGEXP
REGEXP
REGEXP_EXTENDED
TIME_REGEXP

Public Instance Methods

configure(conf) click to toggle source
Calls superclass method
# File lib/fluent/plugin/parser_nfct.rb, line 39
def configure(conf)
  super
  @regexp = @extended ? REGEXP_EXTENDED : REGEXP
  if @ktimestamp
    @time_parser = Strptime.new('%b %d %H:%M:%S %Y')
  end
end
parse(text) { |nil, nil| ... } click to toggle source
# File lib/fluent/plugin/parser_nfct.rb, line 47
def parse(text)
  m = text.match(@regexp)
  unless m
    yield nil, nil
    return
  end

  r = m.named_captures
  %w(protonum l3protonum timeout).each do |k|
    r[k] = r[k].to_i if r[k]
  end

  if @ktimestamp
    parts = r.delete('remaining')&.scan(LABEL_SCAN).flatten || []
  else
    parts = r.delete('remaining')&.split(DELIMITER) || []
  end
  parts.each do |part|
    case
    when @ktimestamp && part.match?(TIME_REGEXP)
      k,v = part[1..-2].split(?=,2)
      begin
        r[k] = @time_parser.execi(v[4..-1])
      rescue ArgumentError
      end
    when part[0] == '['
      r[part[1..-2].downcase] = true
    else
      k,v = part.split(?=, 2)
      if v.match(NUM_REGEXP)
        r[k] = v.to_i
      else
        r[k] = v
      end
    end
  end
  time, value = convert_values(parse_time(r), r)
  yield time, value
end