Class: Shell::Filter

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/shell/filter.rb

Overview

Filter A method to require

each()

Direct Known Subclasses

BuiltInCommand, SystemCommand

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#inputObject

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



86
87
88
# File 'lib/shell/filter.rb', line 86

def + (filter)
  Join.new(@shell, self, filter)
end

#<(src) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/shell/filter.rb', line 40

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



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/shell/filter.rb', line 53

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



70
71
72
73
74
75
76
# File 'lib/shell/filter.rb', line 70

def >> (to)
  begin
	Shell.cd(@shell.pwd).append(to, self)
  rescue CantApplyMethod
	Shell.Fail Error::CantApplyMethod, ">>", to.class
  end
end

#each(rs = nil) ⇒ Object



33
34
35
36
37
38
# File 'lib/shell/filter.rb', line 33

def each(rs = nil)
  rs = @shell.record_separator unless rs
  if @input
	@input.each(rs){|l| yield l}
  end
end

#inspectObject



102
103
104
105
106
107
108
# File 'lib/shell/filter.rb', line 102

def inspect
  if @shell.debug.kind_of?(Integer) && @shell.debug > 2
	super
  else
	to_s
  end
end

#to_aObject



90
91
92
93
94
# File 'lib/shell/filter.rb', line 90

def to_a
  ary = []
  each(){|l| ary.push l}
  ary
end

#to_sObject



96
97
98
99
100
# File 'lib/shell/filter.rb', line 96

def to_s
  str = ""
  each(){|l| str.concat l}
  str
end

#|(filter) ⇒ Object



78
79
80
81
82
83
84
# File 'lib/shell/filter.rb', line 78

def | (filter)
  filter.input = self
  if active?
	@shell.process_controller.start_job filter
  end
  filter
end