Class: Shell::Filter
- Inherits:
-
Object
- Object
- Shell::Filter
- Includes:
- Enumerable
- Defined in:
- lib/shell/filter.rb
Overview
Filter A method to require
each()
Instance Attribute Summary (collapse)
-
- (Object) input
Returns the value of attribute input.
Instance Method Summary (collapse)
- - (Object) +(filter)
- - (Object) <(src)
- - (Object) >(to)
- - (Object) >>(to)
- - (Object) each(rs = nil)
-
- (Filter) initialize(sh)
constructor
A new instance of Filter.
- - (Object) inspect
- - (Object) to_a
- - (Object) to_s
- - (Object) |(filter)
Methods included from Enumerable
Constructor Details
- (Filter) initialize(sh)
A new instance of Filter
21 22 23 24 |
# File 'lib/shell/filter.rb', line 21 def initialize(sh) @shell = sh # parent shell @input = nil # input filter end |
Instance Attribute Details
- (Object) input
Returns the value of attribute input
26 27 28 |
# File 'lib/shell/filter.rb', line 26 def input @input end |
Instance Method Details
- (Object) +(filter)
85 86 87 |
# File 'lib/shell/filter.rb', line 85 def + (filter) Join.new(@shell, self, filter) end |
- (Object) <(src)
39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/shell/filter.rb', line 39 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 |
- (Object) >(to)
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/shell/filter.rb', line 52 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 |
- (Object) >>(to)
69 70 71 72 73 74 75 |
# File 'lib/shell/filter.rb', line 69 def >> (to) begin Shell.cd(@shell.pwd).append(to, self) rescue CantApplyMethod Shell.Fail Error::CantApplyMethod, ">>", to.class end end |
- (Object) each(rs = nil)
32 33 34 35 36 37 |
# File 'lib/shell/filter.rb', line 32 def each(rs = nil) rs = @shell.record_separator unless rs if @input @input.each(rs){|l| yield l} end end |
- (Object) inspect
101 102 103 104 105 106 107 |
# File 'lib/shell/filter.rb', line 101 def inspect if @shell.debug.kind_of?(Integer) && @shell.debug > 2 super else to_s end end |
- (Object) to_a
89 90 91 92 93 |
# File 'lib/shell/filter.rb', line 89 def to_a ary = [] each(){|l| ary.push l} ary end |
- (Object) to_s
95 96 97 98 99 |
# File 'lib/shell/filter.rb', line 95 def to_s str = "" each(){|l| str.concat l} str end |
- (Object) |(filter)
77 78 79 80 81 82 83 |
# File 'lib/shell/filter.rb', line 77 def | (filter) filter.input = self if active? @shell.process_controller.start_job filter end filter end |