Class: Clusta::Transforms::EdgesToNeighborhoods::Reducer

Inherits:
Wukong::Streamer::AccumulatingReducer
  • Object
show all
Includes:
Wukong::Streamer::StructRecordizer
Defined in:
lib/clusta/transforms/edges_to_neighborhoods.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#directedObject

Returns the value of attribute directed.



23
24
25
# File 'lib/clusta/transforms/edges_to_neighborhoods.rb', line 23

def directed
  @directed
end

#neighborsObject

Returns the value of attribute neighbors.



23
24
25
# File 'lib/clusta/transforms/edges_to_neighborhoods.rb', line 23

def neighbors
  @neighbors
end

Instance Method Details

#accumulate(new_edge, *record) ⇒ Object



38
39
40
# File 'lib/clusta/transforms/edges_to_neighborhoods.rb', line 38

def accumulate new_edge, *record
  self.neighbors << new_edge.neighbor
end

#finalize(&block) ⇒ Object



42
43
44
45
46
47
48
# File 'lib/clusta/transforms/edges_to_neighborhoods.rb', line 42

def finalize &block
  if directed
    emit Geometry::DirectedNeighborhood.new(vertex_label, *neighbors)
  else
    emit Geometry::Neighborhood.new(vertex_label, *neighbors)
  end
end

#get_key(new_edge, *record) ⇒ Object



29
30
31
# File 'lib/clusta/transforms/edges_to_neighborhoods.rb', line 29

def get_key new_edge, *record
  new_edge.source_label
end

#start!(new_edge, *record) ⇒ Object



33
34
35
36
# File 'lib/clusta/transforms/edges_to_neighborhoods.rb', line 33

def start! new_edge, *record
  self.neighbors   = []
  self.directed = new_edge.directed?
end