# class Shell::Filter

Any result of command execution is a Filter.

This class includes Enumerable, therefore a Filter object can use all Enumerable facilities.

### Attributes

input[R]

### Public Class Methods

new(sh) click to toggle source

    # File lib/shell/filter.rb, line 22
    def initialize(sh)
      @shell = sh         # parent shell
      @input = nil        # input filter
    end

### Public Instance Methods

filter1 + filter2 click to toggle source

Outputs `filter1`, and then `filter2` using Join.new

    # File lib/shell/filter.rb, line 113
    def +(filter)
      Join.new(@shell, self, filter)
    end

< source click to toggle source

Inputs from `source`, which is either a string of a file name or an IO object.

    # 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, "<", src.class
      end
    end

> source click to toggle source

Outputs from `source`, which is either a string of a file name or an IO object.

    # 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

>> source click to toggle source

Appends the output to `source`, which is either a string of a file name or an IO object.

    # 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(record_separator=nil) { block } click to toggle source

Iterates a block for each line.

    # 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

input=(filter) click to toggle source

    # File lib/shell/filter.rb, line 29
    def input=(filter)
      @input = filter
    end

inspect() click to toggle source
Calls superclass method Object#inspect

    # 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() click to toggle source

    # File lib/shell/filter.rb, line 117
    def to_a
      ary = []
      each(){|l| ary.push l}
      ary
    end

to_s() click to toggle source

    # File lib/shell/filter.rb, line 123
    def to_s
      str = ""
      each(){|l| str.concat l}
      str
    end

| filter click to toggle source

Processes a pipeline.

    # File lib/shell/filter.rb, line 101
    def |(filter)
      filter.input = self
      if active?
        @shell.process_controller.start_job filter
      end
      filter
    end