Class: Tailnudge::Reader

Inherits:
EventMachine::FileTail
  • Object
show all
Defined in:
lib/tailnudge/reader.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, startpos = -1)) ⇒ Reader

Returns a new instance of Reader.



15
16
17
18
# File 'lib/tailnudge/reader.rb', line 15

def initialize(path, startpos=-1)
  super(path, startpos)
  @buffer = BufferedTokenizer.new
end

Class Method Details

.extract(line) ⇒ Object



5
6
7
8
9
10
11
12
13
# File 'lib/tailnudge/reader.rb', line 5

def self.extract(line)
  Tailnudge.patterns.each do |pattern|
    match = pattern.match(line)
    if match
      return Result.new(match, line)
    end
  end
  nil
end

Instance Method Details

#receive_data(data) ⇒ Object



20
21
22
23
24
25
26
27
# File 'lib/tailnudge/reader.rb', line 20

def receive_data(data)
  @buffer.extract(data).each do |line|
    result = self.class.extract(line)
    if result
      Notification.create(result)
    end
  end
end