class Ke::CappedSample

Public Class Methods

new(limit) click to toggle source
# File lib/ke/capped_sample.rb, line 3
def initialize(limit)
  @array = []
  @limit = limit
end

Public Instance Methods

<<(element)
Alias for: push
mean() click to toggle source
# File lib/ke/capped_sample.rb, line 24
def mean
  array_mean @array
end
mean_iqr() click to toggle source
# File lib/ke/capped_sample.rb, line 28
def mean_iqr
  array_sorted = @array.sort
  array_size = @array.size
  iqr = array_sorted[(array_size * 0.25).floor..(array_size * 0.75).ceil]
  array_mean iqr
end
push(element) click to toggle source
# File lib/ke/capped_sample.rb, line 8
def push(element)
  @array << element
  @array.shift if @array.size > @limit
  self
end
Also aliased as: <<
size() click to toggle source
# File lib/ke/capped_sample.rb, line 15
def size
  @array.size
end
to_a() click to toggle source
# File lib/ke/capped_sample.rb, line 19
def to_a
  @array.dup
end
Also aliased as: to_ary
to_ary()
Alias for: to_a
to_s() click to toggle source
# File lib/ke/capped_sample.rb, line 35
def to_s
  "#<CappedSample: #{@array.inspect}>"
end

Private Instance Methods

array_mean(array) click to toggle source
# File lib/ke/capped_sample.rb, line 41
def array_mean(array)
  if @array.size > 0
    @array.inject(:+) / @array.size.to_f
  else
    0
  end
end