Class: Pacer::Transform::SortSection::CustomSortPipe

Inherits:
SortBySectionPipe show all
Defined in:
lib/pacer/transform/sort_section.rb

Instance Attribute Summary collapse

Attributes inherited from SortBySectionPipe

#getPathToHere, #nil_value, #pf_1, #pf_2, #route, #section, #to_emit, #to_sort

Attributes inherited from Pipes::RubyPipe

#starts

Instance Method Summary collapse

Methods inherited from SortBySectionPipe

#on_element, #processNextStart, #setStarts

Methods inherited from Pipes::RubyPipe

#enablePath, #reset, #setStarts

Constructor Details

#initialize(route, visitor_pipe, sort_block, graph, wrapper) ⇒ CustomSortPipe

Returns a new instance of CustomSortPipe.



163
164
165
166
167
168
# File 'lib/pacer/transform/sort_section.rb', line 163

def initialize(route, visitor_pipe, sort_block, graph, wrapper)
  super route, visitor_pipe, nil, nil
  @sort_block = sort_block
  @graph = graph
  @wrapper = wrapper
end

Instance Attribute Details

#sort_blockObject (readonly)

Returns the value of attribute sort_block.



161
162
163
# File 'lib/pacer/transform/sort_section.rb', line 161

def sort_block
  @sort_block
end

Instance Method Details

#after_elementObject



170
171
172
173
174
175
176
177
178
179
180
181
# File 'lib/pacer/transform/sort_section.rb', line 170

def after_element
  if to_sort.any?
    to_sort.map! { |e| [ @wrapper.new(@graph, e.first), e.last ] }
    sorted = to_sort.sort { |a, b| @sort_block.call a.first, b.first }
    if route.element_type == :vertex || route.element_type == :edge
      to_emit.concat sorted.map { |e| [ e.first.element, e.last ] }
    else
      to_emit.concat sorted
    end
    @to_sort.clear
  end
end