class Tefil::LineSubstituter

Public Class Methods

new(old_str, new_str, options = {}) click to toggle source
Calls superclass method Tefil::TextFilterBase::new
# 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

Public Instance Methods

process_stream(in_io, out_io) click to toggle source
# 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