Class: Memory::Aggregate::Total

Inherits:
Struct
  • Object
show all
Defined in:
lib/memory/aggregate.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeTotal

Returns a new instance of Total.



29
30
31
# File 'lib/memory/aggregate.rb', line 29

def initialize
  super(0, 0)
end

Instance Attribute Details

#countObject

Returns the value of attribute count

Returns:

  • (Object)

    the current value of count



28
29
30
# File 'lib/memory/aggregate.rb', line 28

def count
  @count
end

#memoryObject

Returns the value of attribute memory

Returns:

  • (Object)

    the current value of memory



28
29
30
# File 'lib/memory/aggregate.rb', line 28

def memory
  @memory
end

Instance Method Details

#<<(allocation) ⇒ Object



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

def << allocation
  self.memory += allocation.size
  self.count += 1
end

#as_jsonObject



46
47
48
49
50
51
# File 'lib/memory/aggregate.rb', line 46

def as_json
  {
    memory: memory,
    count: count
  }
end

#formatted_memoryObject



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

def formatted_memory
  self.memory
end

#to_sObject



42
43
44
# File 'lib/memory/aggregate.rb', line 42

def to_s
  "(#{Memory.formatted_bytes memory} in #{count} allocations)"
end