Class: Tresse::Group

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name = nil) ⇒ Group

Returns a new instance of Group.



137
138
139
140
141
142
143
144
145
146
147
148
# File 'lib/tresse.rb', line 137

def initialize(name=nil)

  @name = name

  @batches = []
  @launched = false
  @maps = [ nil ]

  @reduce = nil
  @reduce_mutex = Mutex.new
  @reduction_queue = Queue.new
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



135
136
137
# File 'lib/tresse.rb', line 135

def name
  @name
end

Instance Method Details

#each(&block) ⇒ Object

mapping



176
177
178
179
# File 'lib/tresse.rb', line 176

def each(&block)

  do_map(:each, block)
end

#flattenObject Also known as: values



195
196
197
198
199
200
201
202
203
204
205
# File 'lib/tresse.rb', line 195

def flatten

  do_reduce(
    [],
    lambda { |a, e|
      if e.respond_to?(:to_a) && ! e.is_a?(Hash)
        a.concat(e.to_a)
      else
        a.push(e)
      end })
end

#map(&block) ⇒ Object



181
182
183
184
# File 'lib/tresse.rb', line 181

def map(&block)

  do_map(:map, block)
end

#reduce(target, &block) ⇒ Object Also known as: inject

reducing



189
190
191
192
# File 'lib/tresse.rb', line 189

def reduce(target, &block)

  do_reduce(target, block)
end

#source(&block) ⇒ Object

sourcing methods



153
154
155
156
157
158
# File 'lib/tresse.rb', line 153

def source(&block)

  @batches << Tresse::Batch.new(self, block)

  self
end

#source_each(collection, &block) ⇒ Object



160
161
162
163
164
165
166
167
168
169
170
171
# File 'lib/tresse.rb', line 160

def source_each(collection, &block)

  if collection.is_a?(Hash)
    collection.each { |k, v|
      source { Tresse.call_block(block, [ k, v ]) } }
  else
    collection.each_with_index { |e, i|
      source { Tresse.call_block(block, [ e, i ]) } }
  end

  self
end