Class: Shell::Filter
Overview
Any result of command execution is a Filter.
This class includes Enumerable, therefore a Filter object can use all Enumerable facilities.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#input ⇒ Object
Returns the value of attribute input.
Instance Method Summary collapse
-
#+(filter) ⇒ Object
call-seq: filter1 + filter2.
-
#<(src) ⇒ Object
call-seq: < source.
-
#>(to) ⇒ Object
call-seq: > source.
-
#>>(to) ⇒ Object
call-seq: >> source.
-
#each(rs = nil) ⇒ Object
call-seq: each(record_separator=nil) { block }.
-
#initialize(sh) ⇒ Filter
constructor
A new instance of Filter.
- #inspect ⇒ Object
- #to_a ⇒ Object
- #to_s ⇒ Object
-
#|(filter) ⇒ Object
call-seq: | filter.
Constructor Details
#initialize(sh) ⇒ Filter
Returns a new instance of Filter.
22 23 24 25 |
# File 'lib/shell/filter.rb', line 22 def initialize(sh) @shell = sh # parent shell @input = nil # input filter end |
Instance Attribute Details
#input ⇒ Object
Returns the value of attribute input.
27 28 29 |
# File 'lib/shell/filter.rb', line 27 def input @input end |
Instance Method Details
#+(filter) ⇒ Object
call-seq:
filter1 + filter2
Outputs filter1
, and then filter2
using Join.new
113 114 115 |
# File 'lib/shell/filter.rb', line 113 def + (filter) Join.new(@shell, self, filter) end |
#<(src) ⇒ Object
call-seq:
< source
Inputs from source
, which is either a string of a file name or an IO object.
49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/shell/filter.rb', line 49 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 |
#>(to) ⇒ Object
call-seq:
> source
Outputs from source
, which is either a string of a file name or an IO object.
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/shell/filter.rb', line 67 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 |
#>>(to) ⇒ Object
call-seq:
>> source
Appends the output to source
, which is either a string of a file name or an IO object.
89 90 91 92 93 94 95 |
# File 'lib/shell/filter.rb', line 89 def >> (to) begin Shell.cd(@shell.pwd).append(to, self) rescue CantApplyMethod Shell.Fail Error::CantApplyMethod, ">>", to.class end end |
#each(rs = nil) ⇒ Object
call-seq:
each(record_separator=nil) { block }
Iterates a block for each line.
37 38 39 40 41 42 |
# File 'lib/shell/filter.rb', line 37 def each(rs = nil) rs = @shell.record_separator unless rs if @input @input.each(rs){|l| yield l} end end |
#inspect ⇒ Object
129 130 131 132 133 134 135 |
# File 'lib/shell/filter.rb', line 129 def inspect if @shell.debug.kind_of?(Integer) && @shell.debug > 2 super else to_s end end |
#to_a ⇒ Object
117 118 119 120 121 |
# File 'lib/shell/filter.rb', line 117 def to_a ary = [] each(){|l| ary.push l} ary end |
#to_s ⇒ Object
123 124 125 126 127 |
# File 'lib/shell/filter.rb', line 123 def to_s str = "" each(){|l| str.concat l} str end |
#|(filter) ⇒ Object
call-seq:
| filter
Processes a pipeline.
101 102 103 104 105 106 107 |
# File 'lib/shell/filter.rb', line 101 def | (filter) filter.input = self if active? @shell.process_controller.start_job filter end filter end |