textfilter.rb

version 0.1 - Nov.10.2000

目的

一般的なテキストフィルタを作る。

インクルードしているmodule

Enumerable

メソッド

new(source-path, destination-path, filter)
source-path内のファイルで、filterと===を満たすものをdestination-pathに書き出すインスタンスを作る。
each(prefilter, postfilter)
各ファイルについて処理を行う。引数はひとつ。
それぞれProcメソッドを渡す。
TextFilter.toeucとTextFilter.tosjisが定義済み。

バグ

サブディレクトリを考慮していません。

使用例

eucフィルタ (srcディレクトリの.txtファイルをdestにeucに変換してコピーする)

require 'textfilter'

TextFilter.new('src', 'dest', '\.txt$').each(TextFilter.toeuc) do |text|
  text
end

htmlフィルタのスケルトン (ここではEUCに変換して処理し、SJISで書き出す。)

require 'textfilter'

TextFilter.new('src', 'dest', '\.html$').each(TextFilter.toeuc, TextFilter.tosjis) do |html|
  html.gsub("日本語", "Japanese")
  html
end
download

back