Class: Bookwatch::Streams::FilterStream

Inherits:
Object
  • Object
show all
Defined in:
lib/bookwatch/streams/filter_stream.rb

Instance Method Summary collapse

Constructor Details

#initialize(matcher_regex, stream) ⇒ FilterStream

Returns a new instance of FilterStream.



4
5
6
7
# File 'lib/bookwatch/streams/filter_stream.rb', line 4

def initialize(matcher_regex, stream)
  @matcher_regex = matcher_regex
  @stream = stream
end

Instance Method Details

#<<(line) ⇒ Object



13
14
15
# File 'lib/bookwatch/streams/filter_stream.rb', line 13

def <<(line)
  stream << line.gsub("\n", '') if line.match(matcher_regex)
end

#puts(line) ⇒ Object



9
10
11
# File 'lib/bookwatch/streams/filter_stream.rb', line 9

def puts(line)
  stream.puts(line.gsub("\n", '')) if line.match(matcher_regex)
end