Class: Tailstrom::TailReader
- Inherits:
-
Object
- Object
- Tailstrom::TailReader
- Defined in:
- lib/tailstrom/tail_reader.rb
Instance Method Summary collapse
- #each_line(&block) ⇒ Object
- #eof? ⇒ Boolean
- #format_value(value) ⇒ Object
-
#initialize(infile, options = {}) ⇒ TailReader
constructor
A new instance of TailReader.
- #parse_line(line) ⇒ Object
Constructor Details
#initialize(infile, options = {}) ⇒ TailReader
Returns a new instance of TailReader.
3 4 5 6 |
# File 'lib/tailstrom/tail_reader.rb', line 3 def initialize(infile, ={}) @infile = infile @options = end |
Instance Method Details
#each_line(&block) ⇒ Object
8 9 10 11 12 13 14 |
# File 'lib/tailstrom/tail_reader.rb', line 8 def each_line(&block) if @options[:async] Thread.new { _each_line &block } else _each_line &block end end |
#eof? ⇒ Boolean
27 28 29 |
# File 'lib/tailstrom/tail_reader.rb', line 27 def eof? @eof end |
#format_value(value) ⇒ Object
50 51 52 |
# File 'lib/tailstrom/tail_reader.rb', line 50 def format_value(value) value =~ /\./ ? value.to_f : value.to_i end |
#parse_line(line) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/tailstrom/tail_reader.rb', line 31 def parse_line(line) col = line.split @options[:delimiter] value = @options[:field] ? col[@options[:field]] : line value = format_value value key = @options[:key] ? col[@options[:key]] : :nil in_filter = @options[:in_filter] if @options[:map] binding.eval(@options[:map]) value = format_value value end if in_filter return nil unless binding.eval(in_filter) end { :line => line, :columns => col, :key => key, :value => value } end |