Class: Statlysis::MapReduce

Inherits:
Object
  • Object
show all
Defined in:
lib/statlysis/map_reduce.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(mongoid_scope, mapreduce_javascript) ⇒ MapReduce

Returns a new instance of MapReduce.



10
11
12
13
14
15
16
# File 'lib/statlysis/map_reduce.rb', line 10

def initialize mongoid_scope, mapreduce_javascript
  mr.mongoid_scope = mongoid_scope
  mr.mapreduce_javascript = mapreduce_javascript
  mr.is_use_inline = true
  mr.identify = Time.now.strftime("%m%d_%H%M%S")
  mr
end

Instance Attribute Details

#identifyObject

Returns the value of attribute identify.



9
10
11
# File 'lib/statlysis/map_reduce.rb', line 9

def identify
  @identify
end

#is_use_inlineObject

Returns the value of attribute is_use_inline.



9
10
11
# File 'lib/statlysis/map_reduce.rb', line 9

def is_use_inline
  @is_use_inline
end

#mapreduce_javascriptObject (readonly)

Returns the value of attribute mapreduce_javascript.



7
8
9
# File 'lib/statlysis/map_reduce.rb', line 7

def mapreduce_javascript
  @mapreduce_javascript
end

#mongoid_scopeObject (readonly)

Returns the value of attribute mongoid_scope.



7
8
9
# File 'lib/statlysis/map_reduce.rb', line 7

def mongoid_scope
  @mongoid_scope
end

#mr_collectionObject

Returns the value of attribute mr_collection.



8
9
10
# File 'lib/statlysis/map_reduce.rb', line 8

def mr_collection
  @mr_collection
end

#resultsObject

Returns the value of attribute results.



8
9
10
# File 'lib/statlysis/map_reduce.rb', line 8

def results
  @results
end

Instance Method Details

#mrObject



29
# File 'lib/statlysis/map_reduce.rb', line 29

def mr; self end

#out_collection_nameObject



28
# File 'lib/statlysis/map_reduce.rb', line 28

def out_collection_name; "mr_#{mr.mongoid_scope.collection_name}_#{mr.identify}" end

#outputObject



24
25
26
# File 'lib/statlysis/map_reduce.rb', line 24

def output
  mr.results.output
end

#runObject



18
19
20
21
22
# File 'lib/statlysis/map_reduce.rb', line 18

def run
  # TODO collection for large
  mr.results = Results.new mr.mongoid_scope.map_reduce(mapreduce_javascript.map_func, mapreduce_javascript.reduce_func).out(:replace => out_collection_name)
  self
end