Class: Brainstorm::Aggregator

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

Instance Method Summary collapse

Methods inherited from Neuron

#>>

Constructor Details

#initializeAggregator

Returns a new instance of Aggregator.



168
169
170
171
172
# File 'lib/brainstorm.rb', line 168

def initialize
  @buffer = []
  
  @is_capturing = false
end

Instance Method Details

#call(item) ⇒ Object



174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
# File 'lib/brainstorm.rb', line 174

def call(item)
  if @is_capturing
    if item.is_a? Start
      # TODO: Improve error-handling here
      $stderr.puts "Unexpected 'Start' token encountered"
    elsif item.is_a? Finish
      fire @buffer.dup
      @is_capturing = false
    elsif item.is_a? Value
      @buffer.push item.value
    else
      # TODO: Improve error-handling here
      $stderr.puts "Non-aggregate token encountered"
    end
  else
    if item.is_a? Start
      @buffer       = []
      @is_capturing = true
    elsif item.is_a? Finish
      # TODO: Improve error-handling here
      $stderr.puts "Unexpected 'Finish' token encountered"
    elsif item.is_a? Value
      # Just ignore the value
    else
      # TODO: Improve error-handling here
      $stderr.puts "Non-aggregate token encountered"
    end
  end
end