| Class | Shell::Filter |
| In: |
lib/shell/filter.rb
|
| Parent: | Object |
| input | [R] |
# File lib/shell/filter.rb, line 22
22: def initialize(sh)
23: @shell = sh # parent shell
24: @input = nil # input filter
25: end
# File lib/shell/filter.rb, line 40
40: def < (src)
41: case src
42: when String
43: cat = Cat.new(@shell, src)
44: cat | self
45: when IO
46: self.input = src
47: self
48: else
49: Shell.Fail Error::CantApplyMethod, "<", to.class
50: end
51: end
# File lib/shell/filter.rb, line 53
53: def > (to)
54: case to
55: when String
56: dst = @shell.open(to, "w")
57: begin
58: each(){|l| dst << l}
59: ensure
60: dst.close
61: end
62: when IO
63: each(){|l| to << l}
64: else
65: Shell.Fail Error::CantApplyMethod, ">", to.class
66: end
67: self
68: end
# File lib/shell/filter.rb, line 70
70: def >> (to)
71: begin
72: Shell.cd(@shell.pwd).append(to, self)
73: rescue CantApplyMethod
74: Shell.Fail Error::CantApplyMethod, ">>", to.class
75: end
76: end
# File lib/shell/filter.rb, line 33
33: def each(rs = nil)
34: rs = @shell.record_separator unless rs
35: if @input
36: @input.each(rs){|l| yield l}
37: end
38: end
# File lib/shell/filter.rb, line 102
102: def inspect
103: if @shell.debug.kind_of?(Integer) && @shell.debug > 2
104: super
105: else
106: to_s
107: end
108: end
# File lib/shell/filter.rb, line 90
90: def to_a
91: ary = []
92: each(){|l| ary.push l}
93: ary
94: end