Class: Fibeline::GenericElement
- Inherits:
-
Object
- Object
- Fibeline::GenericElement
show all
- Includes:
- Enumerable
- Defined in:
- lib/fibeline/generic_element.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
Returns a new instance of GenericElement.
9
10
11
12
13
14
15
|
# File 'lib/fibeline/generic_element.rb', line 9
def initialize
@transformer ||= method(:transform)
@filter ||= method(:filter)
@fiber_delegate = Fiber.new do
process
end
end
|
Instance Attribute Details
#source ⇒ Object
43
44
45
|
# File 'lib/fibeline/generic_element.rb', line 43
def source
@source ||= NullPump.new
end
|
Instance Method Details
#each ⇒ Object
17
18
19
20
21
|
# File 'lib/fibeline/generic_element.rb', line 17
def each
while (value = resume)
yield value
end
end
|
#filter(value) ⇒ Object
59
60
61
|
# File 'lib/fibeline/generic_element.rb', line 59
def filter(value)
true
end
|
#handle_value(value) ⇒ Object
39
40
41
|
# File 'lib/fibeline/generic_element.rb', line 39
def handle_value(value)
output(@transformer.call(value)) if @filter.call(value)
end
|
47
48
49
|
# File 'lib/fibeline/generic_element.rb', line 47
def input
source.resume
end
|
#output(value) ⇒ Object
51
52
53
|
# File 'lib/fibeline/generic_element.rb', line 51
def output(value)
Fiber.yield(value)
end
|
#process ⇒ Object
33
34
35
36
37
|
# File 'lib/fibeline/generic_element.rb', line 33
def process
while (value = input)
handle_value(value)
end
end
|
#resume ⇒ Object
29
30
31
|
# File 'lib/fibeline/generic_element.rb', line 29
def resume
@fiber_delegate.resume
end
|
55
56
57
|
# File 'lib/fibeline/generic_element.rb', line 55
def transform(value)
value
end
|
#|(other = nil, &block) ⇒ Object
23
24
25
26
27
|
# File 'lib/fibeline/generic_element.rb', line 23
def |(other=nil, &block)
other = Transformer.new(&block) if block
other.source = self
other
end
|