Sha256: d22c77c972f9a4c47a3647475d555d464110f00ef3ad3d9fdb01d77a9a5f00f4

Contents?: true

Size: 684 Bytes

Versions: 2

Compression:

Stored size: 684 Bytes

Contents

module Tailstrom
  class TailReader
    def initialize(infile, options={})
      @infile = infile
      @options = options
    end

    def each_line
      @infile.each_line do |line|
        result = parse_line(line)
        yield result if result
      end
    end

    def parse_line(line)
      columns = line.split @options[:delimiter]
      value = @options[:field] ? columns[@options[:field]] : line
      value = value =~ /\./ ? value.to_f : value.to_i

      if @options[:filter]
        v, cols = value, columns # shorthands
        return nil unless binding.eval(@options[:filter])
      end

      { :line => line, :columns => columns, :value => value }
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
tailstrom-0.0.3 lib/tailstrom/tail_reader.rb
tailstrom-0.0.2 lib/tailstrom/tail_reader.rb