Class: Accumulator
- Inherits:
-
Object
- Object
- Accumulator
- Defined in:
- lib/who_called_me/who_called_me.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #data_only_top ⇒ Object
-
#initialize ⇒ Accumulator
constructor
A new instance of Accumulator.
- #keys ⇒ Object
- #record_trace(key, trace) ⇒ Object
Constructor Details
#initialize ⇒ Accumulator
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
#data ⇒ Object (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_top ⇒ Object
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 |
#keys ⇒ Object
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 |