Class: FactoryBotProfile::Stat

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

Direct Known Subclasses

ChildStat, FactoryStat

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Stat

Returns a new instance of Stat.



5
6
7
8
9
# File 'lib/factory_bot_profile/stat.rb', line 5

def initialize(name)
  @name = name
  @count = 0
  @total_time = 0
end

Instance Attribute Details

#countObject (readonly)

Returns the value of attribute count.



3
4
5
# File 'lib/factory_bot_profile/stat.rb', line 3

def count
  @count
end

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/factory_bot_profile/stat.rb', line 3

def name
  @name
end

#total_timeObject (readonly)

Returns the value of attribute total_time.



3
4
5
# File 'lib/factory_bot_profile/stat.rb', line 3

def total_time
  @total_time
end

Instance Method Details

#average_timeObject



11
12
13
# File 'lib/factory_bot_profile/stat.rb', line 11

def average_time
  total_time / count
end

#merge!(other) ⇒ Object



15
16
17
18
19
20
# File 'lib/factory_bot_profile/stat.rb', line 15

def merge!(other)
  raise "attempting to merge unrelated stats" if name != other.name

  @count += other.count
  @total_time += other.total_time
end