Sha256: 453f85b28cc9d6e5e827d8e2eaa4d51557edff9fd4098f2dd675d7089a1cec04

Contents?: true

Size: 798 Bytes

Versions: 1

Compression:

Stored size: 798 Bytes

Contents

module LogfileInterval
  class Logfile
    attr_reader :filename, :parser

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

    def exist?
      filename && File.exist?(@filename)
    end

    def first_timestamp
      return unless exist?
      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
      return unless exist?
      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.1 lib/logfile_interval/logfile.rb