class ApacheCrunch::FormatTokenFactory

Generates FormatToken instances.

This class does the work of figuring out which FormatToken subclass to make.

Public Class Methods

from_abbrev(abbrev) click to toggle source

Takes an Apache log format abbreviation and returns a corresponding FormatToken

# File lib/format_token.rb, line 87
def self.from_abbrev(abbrev)
    token_def = TokenDictionary.fetch(abbrev)
    if token_def
        # We found it in the dictionary, so just return a Token based on it
        tok = PredefinedToken.new
        tok.populate!(token_def)
    elsif abbrev !~ /^%/
        tok = StringToken.new
        tok.populate!(abbrev)
    elsif abbrev == "%%"
        tok = StringToken.new
        tok.populate!("%")
    elsif abbrev =~ /^%\{([A-Za-z0-9-]+)\}i/
        # HTTP request header
        tok = ReqheaderToken.new
        tok.populate!($1)
    elsif abbrev =~ /^%\{(.*?):([^}]+)\}r/
        # Arbitrary regex
        tok = RegexToken.new
        tok.populate!($1, $2)
    else
        raise "Unable to parse format definition starting at '#{abbrev}'"
    end

    tok
end