Class: Tefil::LineSubstituter
- Inherits:
-
TextFilterBase
- Object
- TextFilterBase
- Tefil::LineSubstituter
- Defined in:
- lib/tefil/linesubstituter.rb
Instance Method Summary collapse
-
#initialize(old_str, new_str, options = {}) ⇒ LineSubstituter
constructor
A new instance of LineSubstituter.
- #process_stream(in_io, out_io) ⇒ Object
Methods inherited from TextFilterBase
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, = {}) @old_str = old_str @old_str = /#{old_str}/ if [:regexp] @new_str = new_str @global = [:global] super() 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 |