Class: Pipelines::Pipeline
- Inherits:
-
Object
- Object
- Pipelines::Pipeline
- Defined in:
- lib/readingme/pipelines.rb
Overview
Instance Method Summary collapse
- #<<(data) ⇒ Object
- #add(callable) ⇒ Object (also: #|)
- #close ⇒ Object (also: #stop)
- #each(&block) ⇒ Object
-
#initialize ⇒ Pipeline
constructor
A new instance of Pipeline.
- #read ⇒ Object
Constructor Details
#initialize ⇒ Pipeline
Returns a new instance of Pipeline.
14 15 16 |
# File 'lib/readingme/pipelines.rb', line 14 def initialize @output, @input = IO.pipe end |
Instance Method Details
#<<(data) ⇒ Object
30 31 32 33 34 35 |
# File 'lib/readingme/pipelines.rb', line 30 def << data data = Array(data) unless data.is_a? IO data.each do |line| @input.puts line end end |
#add(callable) ⇒ Object Also known as: |
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/readingme/pipelines.rb', line 18 def add callable l_out = @output n_out, n_in = IO.pipe @output = n_out Thread.new do callable.call(l_out, n_in) n_in.close end self end |
#close ⇒ Object Also known as: stop
37 |
# File 'lib/readingme/pipelines.rb', line 37 def close; @input.close; end |
#each(&block) ⇒ Object
41 |
# File 'lib/readingme/pipelines.rb', line 41 def each(&block); @output.each(&block); end |
#read ⇒ Object
40 |
# File 'lib/readingme/pipelines.rb', line 40 def read; @output.read; end |