Class: Memory::ValueAggregate
- Inherits:
-
Object
- Object
- Memory::ValueAggregate
- Defined in:
- lib/memory/aggregate.rb
Instance Attribute Summary collapse
-
#aggregates ⇒ Object
readonly
Returns the value of attribute aggregates.
-
#metric ⇒ Object
readonly
Returns the value of attribute metric.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
Instance Method Summary collapse
- #<<(allocation) ⇒ Object
- #aggregates_by(key) ⇒ Object
- #as_json ⇒ Object
-
#initialize(title, &block) ⇒ ValueAggregate
constructor
A new instance of ValueAggregate.
- #print(io = $stderr, limit: 10, level: 2) ⇒ Object
Constructor Details
#initialize(title, &block) ⇒ ValueAggregate
Returns a new instance of ValueAggregate.
102 103 104 105 106 107 |
# File 'lib/memory/aggregate.rb', line 102 def initialize(title, &block) @title = title @metric = block @aggregates = Hash.new{|h,k| h[k] = Aggregate.new(k.inspect, &@metric)} end |
Instance Attribute Details
#aggregates ⇒ Object (readonly)
Returns the value of attribute aggregates.
111 112 113 |
# File 'lib/memory/aggregate.rb', line 111 def aggregates @aggregates end |
#metric ⇒ Object (readonly)
Returns the value of attribute metric.
110 111 112 |
# File 'lib/memory/aggregate.rb', line 110 def metric @metric end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
109 110 111 |
# File 'lib/memory/aggregate.rb', line 109 def title @title end |
Instance Method Details
#<<(allocation) ⇒ Object
113 114 115 116 117 118 119 |
# File 'lib/memory/aggregate.rb', line 113 def << allocation if value = allocation.value aggregate = @aggregates[value] aggregate << allocation end end |
#aggregates_by(key) ⇒ Object
121 122 123 |
# File 'lib/memory/aggregate.rb', line 121 def aggregates_by(key) @aggregates.sort_by{|value, aggregate| [aggregate.total[key], value]} end |
#as_json ⇒ Object
133 134 135 136 137 138 |
# File 'lib/memory/aggregate.rb', line 133 def as_json { title: @title, aggregates: @aggregates.map{|k, v| [k, v.as_json]} } end |
#print(io = $stderr, limit: 10, level: 2) ⇒ Object
125 126 127 128 129 130 131 |
# File 'lib/memory/aggregate.rb', line 125 def print(io = $stderr, limit: 10, level: 2) io.puts "#{'#' * level} #{@title}", nil aggregates_by(:count).last(limit).reverse_each do |value, aggregate| aggregate.print(io, level: level+1) end end |