Class: Tefil::IndentConverter

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

Overview

! /usr/bin/env ruby coding: utf-8

Instance Method Summary collapse

Methods inherited from TextFilterBase

#filter

Constructor Details

#initialize(old_char, old_width, new_char, new_width, options) ⇒ IndentConverter

Returns a new instance of IndentConverter.



5
6
7
8
9
10
11
# File 'lib/tefil/indentconverter.rb', line 5

def initialize(old_char, old_width, new_char, new_width, options)
  @old_width = old_width
  @new_width = new_width
  @old_char  = old_char 
  @new_char  = new_char 
  super(options)
end

Instance Method Details

#process_stream(in_io, out_io) ⇒ Object



13
14
15
16
17
18
19
20
21
# File 'lib/tefil/indentconverter.rb', line 13

def process_stream(in_io, out_io)
  in_io.readlines.each do |line|
    /^(#{@old_char}*)(.*)$/ =~ line
    indent = $1
    body = $2
    new_indent = indent.size * @new_width / @old_width
    out_io.puts "#{@new_char * new_indent}#{body}"
  end
end