Class: Accumulator

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeAccumulator

Returns a new instance of Accumulator.



16
17
18
# File 'lib/who_called_me/who_called_me.rb', line 16

def initialize
  @data = {}
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



15
16
17
# File 'lib/who_called_me/who_called_me.rb', line 15

def data
  @data
end

Instance Method Details

#[](key) ⇒ Object



38
39
40
# File 'lib/who_called_me/who_called_me.rb', line 38

def [](key)
  data[key]
end

#data_only_topObject



24
25
26
27
28
29
30
31
# File 'lib/who_called_me/who_called_me.rb', line 24

def data_only_top
  {}.tap do |result|
    keys.each do |key|
      traces = data[key]
      result[key] = traces.collect{|trace| trace.first }.uniq
    end
  end
end

#keysObject



20
21
22
# File 'lib/who_called_me/who_called_me.rb', line 20

def keys
  data.keys
end

#record_trace(key, trace) ⇒ Object



33
34
35
36
# File 'lib/who_called_me/who_called_me.rb', line 33

def record_trace(key, trace)
  data[key] ||= []
  data[key] << trace
end