Sha256: afde7b26c3827b415fd62d30dbcc8f8f9ea73669e5fb4d3676886b77453d7587

Contents?: true

Size: 726 Bytes

Versions: 1

Compression:

Stored size: 726 Bytes

Contents

module LogfileInterval
  class Logfile
    attr_reader :filename, :parser

    def initialize(filename, parser)
      @filename = filename
      @parser   = parser
    end

    def first_timestamp
      return nil unless File.exist?(@filename)
      File.open(@filename) do |f|
        while line = f.gets
          if record = parser.create_record(line)
            return record.time
          end
        end
      end
    end

    def each_line
      f = FileBackward.new(@filename)
      while(line = f.gets)
        yield line.chomp
      end
      f.close
    end

    def each_parsed_line
      each_line do |line|
        record = parser.create_record(line)
        yield record if record
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
logfile_interval-1.1.0 lib/logfile_interval/logfile.rb