Class: NetworkResiliency::PowerStats

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

Constant Summary collapse

MIN_VALUE =
1
LOCK =
Thread::Mutex.new
STATS =
{}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(values = []) ⇒ PowerStats

Returns a new instance of PowerStats.



33
34
35
36
37
38
# File 'lib/network_resiliency/power_stats.rb', line 33

def initialize(values = [])
  @lock = Thread::Mutex.new
  reset

  values.each {|x| add(x) }
end

Instance Attribute Details

#nObject (readonly)

Returns the value of attribute n.



11
12
13
# File 'lib/network_resiliency/power_stats.rb', line 11

def n
  @n
end

Class Method Details

.[](key) ⇒ Object



14
15
16
# File 'lib/network_resiliency/power_stats.rb', line 14

def [](key)
  LOCK.synchronize { STATS[key] ||= new }
end

.resetObject



18
19
20
# File 'lib/network_resiliency/power_stats.rb', line 18

def reset
  LOCK.synchronize { STATS.clear }
end

Instance Method Details

#<<(value) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/network_resiliency/power_stats.rb', line 40

def <<(value)
  case value
  when Array
    value.each {|x| add(x) }
  when self.class
    merge!(value)
  else
    add(value)
  end

  self
end

#merge(other) ⇒ Object Also known as: +



90
91
92
# File 'lib/network_resiliency/power_stats.rb', line 90

def merge(other)
  dup.merge!(other)
end

#p99Object



86
87
88
# File 'lib/network_resiliency/power_stats.rb', line 86

def p99
  percentile(99)
end