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

attr_reader :batches



131
132
133
134
135
136
137
138
139
140
141
142
# File 'lib/tresse.rb', line 131

def initialize(name=nil)

  @name = name

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

  @reduce = nil
  @reduce_batches = []
  @reduction_queue = Queue.new
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



128
129
130
# File 'lib/tresse.rb', line 128

def name
  @name
end

Instance Method Details

#each(&block) ⇒ Object

mapping



172
173
174
175
# File 'lib/tresse.rb', line 172

def each(&block)

  do_map(:each, block)
end

#flattenObject Also known as: values



191
192
193
194
# File 'lib/tresse.rb', line 191

def flatten

  do_reduce([], lambda { |a, e| a.concat(e) })
end

#map(&block) ⇒ Object



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

def map(&block)

  do_map(:map, block)
end

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

reducing



185
186
187
188
# File 'lib/tresse.rb', line 185

def reduce(target, &block)

  do_reduce(target, block)
end

#source(o = nil, &block) ⇒ Object

sourcing methods



147
148
149
150
151
152
153
154
# File 'lib/tresse.rb', line 147

def source(o=nil, &block)

  batch = Tresse::Batch.new(self, o ? o : block)

  @batches << batch

  self
end

#source_each(collection, &block) ⇒ Object



156
157
158
159
160
161
162
163
164
165
166
167
# File 'lib/tresse.rb', line 156

def source_each(collection, &block)

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

  self
end