Class
Any result of command execution is a Filter
.
This class includes Enumerable
, therefore a Filter
object can use all Enumerable
facilities.
Attributes
Read
No documentation available
Class Methods
::
lib/shell/filter.rb
View on GitHub
# File tmp/rubies/ruby-2.4.10/lib/shell/filter.rb, line 23
def initialize(sh)
@shell = sh # parent shell
@input = nil # input filter
end
No documentation available
Instance Methods
lib/shell/filter.rb
View on GitHub
# File tmp/rubies/ruby-2.4.10/lib/shell/filter.rb, line 114
def +(filter)
Join.new(@shell, self, filter)
end
Outputs filter1
, and then filter2
using Join.new
#
lib/shell/filter.rb
View on GitHub
# File tmp/rubies/ruby-2.4.10/lib/shell/filter.rb, line 50
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
Inputs from source
, which is either a string of a file name or an IO
object.
#
lib/shell/filter.rb
View on GitHub
# File tmp/rubies/ruby-2.4.10/lib/shell/filter.rb, line 68
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
Outputs from source
, which is either a string of a file name or an IO
object.
lib/shell/filter.rb
View on GitHub
# File tmp/rubies/ruby-2.4.10/lib/shell/filter.rb, line 90
def >>(to)
begin
Shell.cd(@shell.pwd).append(to, self)
rescue CantApplyMethod
Shell.Fail Error::CantApplyMethod, ">>", to.class
end
end
Appends the output to source
, which is either a string of a file name or an IO
object.
lib/shell/filter.rb
View on GitHub
# File tmp/rubies/ruby-2.4.10/lib/shell/filter.rb, line 38
def each(rs = nil)
rs = @shell.record_separator unless rs
if @input
@input.each(rs){|l| yield l}
end
end
Iterates a block for each line.
lib/shell/filter.rb
View on GitHub
# File tmp/rubies/ruby-2.4.10/lib/shell/filter.rb, line 30
def input=(filter)
@input = filter
end
No documentation available
#
lib/shell/filter.rb
View on GitHub
# File tmp/rubies/ruby-2.4.10/lib/shell/filter.rb, line 130
def inspect
if @shell.debug.kind_of?(Integer) && @shell.debug > 2
super
else
to_s
end
end
No documentation available
#
lib/shell/filter.rb
View on GitHub
# File tmp/rubies/ruby-2.4.10/lib/shell/filter.rb, line 118
def to_a
ary = []
each(){|l| ary.push l}
ary
end
No documentation available
#
lib/shell/filter.rb
View on GitHub
# File tmp/rubies/ruby-2.4.10/lib/shell/filter.rb, line 124
def to_s
str = ""
each(){|l| str.concat l}
str
end
No documentation available
#
lib/shell/filter.rb
View on GitHub
# File tmp/rubies/ruby-2.4.10/lib/shell/filter.rb, line 102
def |(filter)
filter.input = self
if active?
@shell.process_controller.start_job filter
end
filter
end
Processes a pipeline.