Class: NCSAParser::Log

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/ncsa-parser/log.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(log, options = {}) ⇒ Log

Returns a new instance of Log.



8
9
10
11
# File 'lib/ncsa-parser/log.rb', line 8

def initialize(log, options = {})
  @log = log
  @parser = Parser.new(options)
end

Instance Attribute Details

#logObject (readonly)

Returns the value of attribute log.



6
7
8
# File 'lib/ncsa-parser/log.rb', line 6

def log
  @log
end

#parserObject (readonly)

Returns the value of attribute parser.



6
7
8
# File 'lib/ncsa-parser/log.rb', line 6

def parser
  @parser
end

Class Method Details

.open(file, options = {}) ⇒ Object



13
14
15
16
17
18
19
20
21
# File 'lib/ncsa-parser/log.rb', line 13

def self.open(file, options = {})
  file = if file.is_a?(String)
    File.open(file)
  else
    file
  end

  self.new(file, options)
end

Instance Method Details

#eachObject



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/ncsa-parser/log.rb', line 23

def each
  if block_given?
    self.log.each do |l|
      yield self.parser.parse_line(l)
    end
  else
    self.log.collect do |l|
      self.parser.parse_line(l)
    end
  end
end

#next_lineObject



35
36
37
38
39
# File 'lib/ncsa-parser/log.rb', line 35

def next_line
  self.parser.parse_line(self.log.gets).tap { |parsed|
    yield parsed if block_given?
  }
end