Class: ApacheCrunch::FormatTokenFactory
- Inherits:
-
Object
- Object
- ApacheCrunch::FormatTokenFactory
- Defined in:
- lib/format_token.rb
Overview
Generates FormatToken instances.
This class does the work of figuring out which FormatToken subclass to make.
Class Method Summary collapse
-
.from_abbrev(abbrev) ⇒ Object
Takes an Apache log format abbreviation and returns a corresponding FormatToken.
Class Method Details
.from_abbrev(abbrev) ⇒ Object
Takes an Apache log format abbreviation and returns a corresponding FormatToken
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# 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 |