diff options
Diffstat (limited to 'ruby_1_8_5/lib/shell/filter.rb')
-rw-r--r-- | ruby_1_8_5/lib/shell/filter.rb | 110 |
1 files changed, 110 insertions, 0 deletions
diff --git a/ruby_1_8_5/lib/shell/filter.rb b/ruby_1_8_5/lib/shell/filter.rb new file mode 100644 index 0000000000..12cc5206f8 --- /dev/null +++ b/ruby_1_8_5/lib/shell/filter.rb @@ -0,0 +1,110 @@ +# +# shell/filter.rb - +# $Release Version: 0.6.0 $ +# $Revision: 1.3.2.1 $ +# $Date: 2004/03/21 12:21:11 $ +# by Keiju ISHITSUKA(Nihon Rational Software Co.,Ltd) +# +# -- +# +# +# + +class Shell + # + # Filter + # A method to require + # each() + # + class Filter + include Enumerable + + def initialize(sh) + @shell = sh # parent shell + @input = nil # input filter + end + + attr_reader :input + + def input=(filter) + @input = filter + end + + def each(rs = nil) + rs = @shell.record_separator unless rs + if @input + @input.each(rs){|l| yield l} + end + end + + def < (src) + case src + when String + cat = Cat.new(@shell, src) + cat | self + when IO + self.input = src + self + else + Shell.Fail Error::CantApplyMethod, "<", to.class + end + end + + def > (to) + case to + when String + dst = @shell.open(to, "w") + begin + each(){|l| dst << l} + ensure + dst.close + end + when IO + each(){|l| to << l} + else + Shell.Fail Error::CantApplyMethod, ">", to.class + end + self + end + + def >> (to) + begin + Shell.cd(@shell.pwd).append(to, self) + rescue CantApplyMethod + Shell.Fail Error::CantApplyMethod, ">>", to.class + end + end + + def | (filter) + filter.input = self + if active? + @shell.process_controller.start_job filter + end + filter + end + + def + (filter) + Join.new(@shell, self, filter) + end + + def to_a + ary = [] + each(){|l| ary.push l} + ary + end + + def to_s + str = "" + each(){|l| str.concat l} + str + end + + def inspect + if @shell.debug.kind_of?(Integer) && @shell.debug > 2 + super + else + to_s + end + end + end +end |