Class: Turbine::Pipeline::Sender

Inherits:
Expander show all
Defined in:
lib/turbine/pipeline/sender.rb

Overview

A segment which transforms its input by sending a message to each input and returning the result.

( Pump.new([1, 2]) | Sender.new(:to_s) ).to_a
# => ['1', '2']

Each item coming from the source segment must have a public method with the same name as the message.

Some methods in Turbine return an Array, Collection, or Enumerator as a sort of “result set” – such as Node#in, Node#descendants, etc. In these cases, each element in the result set is yielded separately before continuing with the next input. See Expander for more details.

Instance Attribute Summary collapse

Attributes inherited from Segment

#source

Instance Method Summary collapse

Methods inherited from Expander

#next

Methods inherited from Segment

#append, #each, #inspect, #next, #rewind, #trace, #tracing=

Constructor Details

#initialize(message, *args) ⇒ Sender

Public: Creates a new Sender segment.

message - The message (method name) to be sent to each value in the

pipeline.

args - Optional arguments to be sent with the message.

Returns a Sender.



26
27
28
29
30
31
# File 'lib/turbine/pipeline/sender.rb', line 26

def initialize(message, *args)
  @message = message
  @args    = args

  super()
end

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



17
18
19
# File 'lib/turbine/pipeline/sender.rb', line 17

def args
  @args
end

#messageObject (readonly)

Returns the value of attribute message.



17
18
19
# File 'lib/turbine/pipeline/sender.rb', line 17

def message
  @message
end

Instance Method Details

#to_sObject

Public: Describes the segments through which each input will pass.

Returns a string.



36
37
38
39
# File 'lib/turbine/pipeline/sender.rb', line 36

def to_s
  "#{ source_to_s } | #{ message.to_s }" \
    "(#{ args.map(&:inspect).join(', ') })"
end