Class: Apache::Log::Entry

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/aplo/entry.rb

Instance Method Summary collapse

Constructor Details

#initialize(attributes) ⇒ Entry

Returns a new instance of Entry.



7
8
9
# File 'lib/aplo/entry.rb', line 7

def initialize(attributes)
  @attributes = attributes.to_hash
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object (private)



38
39
40
41
# File 'lib/aplo/entry.rb', line 38

def method_missing(name, *args, &block)
  return @attributes[name] if @attributes.has_key?(name)
  super name, *args, &block
end

Instance Method Details

#[](key) ⇒ Object



11
12
13
# File 'lib/aplo/entry.rb', line 11

def [](key)
  @attributes[key]
end

#eachObject



15
16
17
# File 'lib/aplo/entry.rb', line 15

def each
  @attributes.each { |key, value| yield key, value }
end

#inspectObject



19
20
21
# File 'lib/aplo/entry.rb', line 19

def inspect
  @@inspect ||= "#<Apache::Log::Entry>"
end

#to_sObject



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/aplo/entry.rb', line 23

def to_s
  inject([]) do |lines, (directive, value)|
    if value.is_a? Hash
      lines << "#{directive}:"
      value.each { |(k, v)| lines << "  #{k}: #{v}" }
    else
      lines << "#{directive}: #{value}"
    end
    next lines
  end * "\n"
end