Class: Pacer::Transform::IntersectSections::IntersectSectionPipe

Inherits:
Pipes::RubyPipe
  • Object
show all
Defined in:
lib/pacer/transform/intersect_sections.rb

Instance Attribute Summary collapse

Attributes inherited from Pipes::RubyPipe

#starts

Instance Method Summary collapse

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_setsObject

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_setObject

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_blockObject (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

#sectionObject (readonly)

Returns the value of attribute section.



76
77
78
# File 'lib/pacer/transform/intersect_sections.rb', line 76

def section
  @section
end

#to_emitObject

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

#processNextStartObject



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