Class: Tefil::LineSubstituter

Inherits:
TextFilterBase show all
Defined in:
lib/tefil/linesubstituter.rb

Instance Method Summary collapse

Methods inherited from TextFilterBase

#filter

Constructor Details

#initialize(old_str, new_str, options = {}) ⇒ LineSubstituter

Returns a new instance of LineSubstituter.



2
3
4
5
6
7
8
# File 'lib/tefil/linesubstituter.rb', line 2

def initialize(old_str, new_str, options = {})
  @old_str  = old_str
  @old_str  = /#{old_str}/ if options[:regexp]
  @new_str  = new_str
  @global = options[:global]
  super(options)
end

Instance Method Details

#process_stream(in_io, out_io) ⇒ Object



10
11
12
13
14
15
16
# File 'lib/tefil/linesubstituter.rb', line 10

def process_stream(in_io, out_io)
  in_io.each do |line|
    method = :sub
    method = :gsub if @global
    out_io.puts line.send(method, @old_str, @new_str)
  end
end