#! /usr/bin/env ruby # coding: utf-8 # # USAGE: textfilter [options] str0 str1 files ... require "pp" require "optparse" require "rubygems" gem "tefil" require "tefil.rb" ## option analysis OPTIONS = {} op = OptionParser.new op.on("-s" , "--sort" , "Sort."){ OPTIONS[:sort] = true} op.on("-r" , "--randomize" , "Randomize."){ OPTIONS[:random] = true} op.on("-o" , "--overwrite" , "Overwrite."){ OPTIONS[:overwrite] = true} op.parse!(ARGV) module TextFilter def self.process_stream(in_io, out_io) in_io.each do |line| if OPTIONS[:sort] out_io.puts line.chomp.split(//).sort.join('') end if OPTIONS[:random] out_io.puts line.chomp.split(//).sort_by{rand}.join('') end end end end OPTIONS[:overwrite] ||= false #pp OPTIONS[:overwrite] #TextFilter.run(ARGV, OPTIONS[:overwrite]) TextFilter.run(ARGV, OPTIONS[:overwrite])