Class: Shell::Filter
- Inherits:
-
Object
show all
- Includes:
- Enumerable
- Defined in:
- lib/shell/filter.rb
Overview
Filter A method to require
each()
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(sh) ⇒ Filter
Returns a new instance of Filter.
21
22
23
24
|
# File 'lib/shell/filter.rb', line 21
def initialize(sh)
@shell = sh @input = nil end
|
Instance Attribute Details
Returns the value of attribute input
26
27
28
|
# File 'lib/shell/filter.rb', line 26
def input
@input
end
|
Instance Method Details
#+(filter) ⇒ Object
85
86
87
|
# File 'lib/shell/filter.rb', line 85
def + (filter)
Join.new(@shell, self, filter)
end
|
#<(src) ⇒ Object
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
|
#>(to) ⇒ Object
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
|
#>>(to) ⇒ Object
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
|
#each(rs = nil) ⇒ Object
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
|
#inspect ⇒ Object
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
|
#to_a ⇒ Object
89
90
91
92
93
|
# File 'lib/shell/filter.rb', line 89
def to_a
ary = []
each(){|l| ary.push l}
ary
end
|
#to_s ⇒ Object
95
96
97
98
99
|
# File 'lib/shell/filter.rb', line 95
def to_s
str = ""
each(){|l| str.concat l}
str
end
|
#|(filter) ⇒ Object
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
|