Class: Pacer::Transform::Reduce::ReducerPipe
- Inherits:
-
Pipes::RubyPipe
- Object
- AbstractPipe
- Pipes::RubyPipe
- Pacer::Transform::Reduce::ReducerPipe
- Defined in:
- lib/pacer/transform/reduce.rb
Instance Attribute Summary collapse
-
#change_value ⇒ Object
readonly
Returns the value of attribute change_value.
-
#changed_value ⇒ Object
Returns the value of attribute changed_value.
-
#enter ⇒ Object
readonly
Returns the value of attribute enter.
-
#leave ⇒ Object
readonly
Returns the value of attribute leave.
-
#next_value ⇒ Object
Returns the value of attribute next_value.
-
#reduce ⇒ Object
readonly
Returns the value of attribute reduce.
-
#value_changed ⇒ Object
Returns the value of attribute value_changed.
Attributes inherited from Pipes::RubyPipe
Instance Method Summary collapse
-
#initialize(back, enter, reduce, leave) ⇒ ReducerPipe
constructor
A new instance of ReducerPipe.
- #processNextStart ⇒ Object
Methods inherited from Pipes::RubyPipe
#enablePath, #reset, #setStarts
Constructor Details
#initialize(back, enter, reduce, leave) ⇒ ReducerPipe
Returns a new instance of ReducerPipe.
101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/pacer/transform/reduce.rb', line 101 def initialize(back, enter, reduce, leave) super() @change_value = proc do |new_value| self.changed_value = new_value self.value_changed = true end @enter = Pacer::Wrappers::WrappingPipeFunction.new back, enter @reduce = Pacer::Wrappers::WrappingPipeFunction.new back, reduce @leave = Pacer::Wrappers::WrappingPipeFunction.new back, leave @next_value = nil end |
Instance Attribute Details
#change_value ⇒ Object (readonly)
Returns the value of attribute change_value.
97 98 99 |
# File 'lib/pacer/transform/reduce.rb', line 97 def change_value @change_value end |
#changed_value ⇒ Object
Returns the value of attribute changed_value.
98 99 100 |
# File 'lib/pacer/transform/reduce.rb', line 98 def changed_value @changed_value end |
#enter ⇒ Object (readonly)
Returns the value of attribute enter.
97 98 99 |
# File 'lib/pacer/transform/reduce.rb', line 97 def enter @enter end |
#leave ⇒ Object (readonly)
Returns the value of attribute leave.
97 98 99 |
# File 'lib/pacer/transform/reduce.rb', line 97 def leave @leave end |
#next_value ⇒ Object
Returns the value of attribute next_value.
99 100 101 |
# File 'lib/pacer/transform/reduce.rb', line 99 def next_value @next_value end |
#reduce ⇒ Object (readonly)
Returns the value of attribute reduce.
97 98 99 |
# File 'lib/pacer/transform/reduce.rb', line 97 def reduce @reduce end |
#value_changed ⇒ Object
Returns the value of attribute value_changed.
98 99 100 |
# File 'lib/pacer/transform/reduce.rb', line 98 def value_changed @value_changed end |
Instance Method Details
#processNextStart ⇒ Object
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/pacer/transform/reduce.rb', line 113 def processNextStart if next_value collecting = true value = next_value self.next_value = nil else collecting = false end leaving = false final_value = nil while raw_element = starts.next if collecting if leave.call_with_args(raw_element, value, change_value) leaving = true return_value = final_value(value) collecting = false else value = reduce.call_with_args(raw_element, value) end end if not collecting value = enter.call raw_element if value collecting = true value = reduce.call_with_args(raw_element, value) end end if leaving self.next_value = value if collecting return return_value end end rescue Pacer::EmptyPipe, java.util.NoSuchElementException if collecting and leave.call_with_args(nil, value, change_value) return final_value(value) end raise EmptyPipe.instance end |