Class: EZproxy::Log

Inherits:
Object
  • Object
show all
Defined in:
lib/ezproxy/log.rb,
lib/ezproxy/log/format.rb

Defined Under Namespace

Classes: Format

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes) ⇒ Log

Returns a new instance of Log.



5
6
7
# File 'lib/ezproxy/log.rb', line 5

def initialize(attributes)
  @format = EZproxy::Log::Format.new(attributes[:format])
end

Instance Attribute Details

#formatObject

Returns the value of attribute format.



3
4
5
# File 'lib/ezproxy/log.rb', line 3

def format
  @format
end

Instance Method Details

#parse_file(filename) ⇒ Object

Load and parse ‘filename`



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/ezproxy/log.rb', line 10

def parse_file(filename)
  matcher = @format.to_regex
  defined_attributes = @format.defined_attributes

  File.open(filename) do |file|
    file.each_line do |line|
      m = line.match(matcher).to_a

      r = {}
      m[1..m.count].zip(defined_attributes).each do |match, attr|
        r[attr[:label]] = match
      end

      if block_given?
        yield r
      else
        r
      end
    end
  end
end