Class: Ke::CappedSample
- Inherits:
-
Object
- Object
- Ke::CappedSample
- Defined in:
- lib/ke/capped_sample.rb
Instance Method Summary collapse
-
#initialize(limit) ⇒ CappedSample
constructor
A new instance of CappedSample.
- #mean ⇒ Object
- #mean_iqr ⇒ Object
- #push(element) ⇒ Object (also: #<<)
- #size ⇒ Object
- #to_a ⇒ Object (also: #to_ary)
- #to_s ⇒ Object
Constructor Details
#initialize(limit) ⇒ CappedSample
Returns a new instance of CappedSample.
3 4 5 6 |
# File 'lib/ke/capped_sample.rb', line 3 def initialize(limit) @array = [] @limit = limit end |
Instance Method Details
#mean ⇒ Object
24 25 26 |
# File 'lib/ke/capped_sample.rb', line 24 def mean array_mean @array end |
#mean_iqr ⇒ Object
28 29 30 31 32 33 |
# 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) ⇒ Object Also known as: <<
8 9 10 11 12 |
# File 'lib/ke/capped_sample.rb', line 8 def push(element) @array << element @array.shift if @array.size > @limit self end |
#size ⇒ Object
15 16 17 |
# File 'lib/ke/capped_sample.rb', line 15 def size @array.size end |
#to_a ⇒ Object Also known as: to_ary
19 20 21 |
# File 'lib/ke/capped_sample.rb', line 19 def to_a @array.dup end |
#to_s ⇒ Object
35 36 37 |
# File 'lib/ke/capped_sample.rb', line 35 def to_s "#<CappedSample: #{@array.inspect}>" end |