Class: Marbu::Builder

Inherits:
Object
  • Object
show all
Defined in:
lib/marbu/builder.rb,
lib/marbu/builders/mongodb.rb

Overview

the builder class is a lightweight container that holds a MapReduceModel and the requester Builder class its basically a front for the internals of the builders

Defined Under Namespace

Classes: Mongodb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(mrm, options = {}) ⇒ Builder

Returns a new instance of Builder.



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/marbu/builder.rb', line 9

def initialize(mrm, options = {})
  if mrm.is_a?(Marbu::Models::MapReduceFinalize)
    @map_reduce_model = mrm
  elsif mrm.is_a?(Hash)
    @map_reduce_model = Marbu::Models::MapReduceFinalize.new(mrm)
  else
    raise Exception.new("Parameter mrm was neither of type MapReduceFinalize nor Hash, but #{mrm.class}. Aborting")
  end

  @builder_clasz    = options[:builder] || Marbu::Builder::Mongodb
  @formatter_clasz  = options[:formatter] || Marbu::Formatter::Dummy
end

Instance Attribute Details

#map_reduce_modelObject

Returns the value of attribute map_reduce_model.



7
8
9
# File 'lib/marbu/builder.rb', line 7

def map_reduce_model
  @map_reduce_model
end

Instance Method Details

#finalize(format = :text) ⇒ Object



30
31
32
# File 'lib/marbu/builder.rb', line 30

def finalize(format = :text)
  @formatter_clasz.perform(@builder_clasz.finalize(@map_reduce_model.finalize, format))
end

#logObject



39
40
41
# File 'lib/marbu/builder.rb', line 39

def log
  self.to_s
end

#map(format = :text) ⇒ Object



22
23
24
# File 'lib/marbu/builder.rb', line 22

def map(format = :text)
  @formatter_clasz.perform(@builder_clasz.map(@map_reduce_model.map, format))
end

#query(format = :text) ⇒ Object



34
35
36
37
# File 'lib/marbu/builder.rb', line 34

def query(format = :text)
  #@builder_clasz.query(@map_reduce_model.query, format)
  @map_reduce_model.query.static
end

#reduce(format = :text) ⇒ Object



26
27
28
# File 'lib/marbu/builder.rb', line 26

def reduce(format = :text)
  @formatter_clasz.perform(@builder_clasz.reduce(@map_reduce_model.reduce, format))
end

#to_sObject



43
44
45
46
47
# File 'lib/marbu/builder.rb', line 43

def to_s
  puts "Map: #{map}"
  puts "Reduce: #{reduce}"
  puts "Finalize: #{finalize}"
end