Class: Apache::Log::Format
- Inherits:
-
Object
- Object
- Apache::Log::Format
- Defined in:
- lib/aplo/format.rb
Instance Method Summary collapse
-
#initialize(format_string) ⇒ Format
constructor
A new instance of Format.
- #parse(str) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(format_string) ⇒ Format
Returns a new instance of Format.
5 6 7 |
# File 'lib/aplo/format.rb', line 5 def initialize(format_string) @format_string = format_string.to_s end |
Instance Method Details
#parse(str) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/aplo/format.rb', line 13 def parse(str) if matchdata = pattern.match(str) data = directives.zip(matchdata.captures).inject({}) do |data, (directive, capture)| if directive.keyed? && !directive.formatted? data[directive.name] ||= {} data[directive.name][directive.key] = directive.process(capture) else data[directive.name] = directive.process(capture) end next data end return Entry.new(data) else raise "failed to match: %p" % str end end |
#to_s ⇒ Object
9 10 11 |
# File 'lib/aplo/format.rb', line 9 def to_s @format_string end |