Class: Pacer::Transform::IntersectSections::IntersectSectionPipe
- Inherits:
-
Pipes::RubyPipe
- Object
- AbstractPipe
- Pipes::RubyPipe
- Pacer::Transform::IntersectSections::IntersectSectionPipe
- Defined in:
- lib/pacer/transform/intersect_sections.rb
Instance Attribute Summary collapse
-
#all_sets ⇒ Object
Returns the value of attribute all_sets.
-
#current_set ⇒ Object
Returns the value of attribute current_set.
-
#reduce_block ⇒ Object
readonly
Returns the value of attribute reduce_block.
-
#section ⇒ Object
readonly
Returns the value of attribute section.
-
#to_emit ⇒ Object
Returns the value of attribute to_emit.
Attributes inherited from Pipes::RubyPipe
Instance Method Summary collapse
-
#initialize(section, operation) ⇒ IntersectSectionPipe
constructor
A new instance of IntersectSectionPipe.
- #on_element(x) ⇒ Object
- #processNextStart ⇒ Object
Methods inherited from Pipes::RubyPipe
#enablePath, #reset, #setStarts
Constructor Details
#initialize(section, operation) ⇒ IntersectSectionPipe
Returns a new instance of IntersectSectionPipe.
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/pacer/transform/intersect_sections.rb', line 79 def initialize(section, operation) super() @section = section case operation when :difference @reduce_block = proc { |a, b| (a - b) + (b - a) } when :left_difference @reduce_block = proc { |a, b| a - b } when :right_difference @reduce_block = proc { |a, b| b - a } when :intersection @reduce_block = proc { |a, b| a.intersection b } end self.all_sets = [] if section section.visitor = self else on_element nil end end |
Instance Attribute Details
#all_sets ⇒ Object
Returns the value of attribute all_sets.
77 78 79 |
# File 'lib/pacer/transform/intersect_sections.rb', line 77 def all_sets @all_sets end |
#current_set ⇒ Object
Returns the value of attribute current_set.
77 78 79 |
# File 'lib/pacer/transform/intersect_sections.rb', line 77 def current_set @current_set end |
#reduce_block ⇒ Object (readonly)
Returns the value of attribute reduce_block.
76 77 78 |
# File 'lib/pacer/transform/intersect_sections.rb', line 76 def reduce_block @reduce_block end |
#section ⇒ Object (readonly)
Returns the value of attribute section.
76 77 78 |
# File 'lib/pacer/transform/intersect_sections.rb', line 76 def section @section end |
#to_emit ⇒ Object
Returns the value of attribute to_emit.
77 78 79 |
# File 'lib/pacer/transform/intersect_sections.rb', line 77 def to_emit @to_emit end |
Instance Method Details
#on_element(x) ⇒ Object
111 112 113 114 |
# File 'lib/pacer/transform/intersect_sections.rb', line 111 def on_element(x) self.current_set = Set[] all_sets << current_set end |
#processNextStart ⇒ Object
100 101 102 103 104 105 106 107 108 109 |
# File 'lib/pacer/transform/intersect_sections.rb', line 100 def processNextStart unless to_emit while starts.hasNext current_set << starts.next end self.to_emit = all_sets.reduce(&reduce_block).to_a end raise EmptyPipe.instance if to_emit.empty? to_emit.shift end |