Class: Pong::Series

Inherits:
Array
  • Object
show all
Defined in:
lib/pong.rb

Constant Summary collapse

MAX =
32767

Instance Method Summary collapse

Instance Method Details

#last(n = MAX) ⇒ Object



15
16
17
18
# File 'lib/pong.rb', line 15

def last(n = MAX)
  num = num(n)
  self.slice(-num, num)
end

#mean(n = MAX) ⇒ Object



26
27
28
# File 'lib/pong.rb', line 26

def mean(n = MAX)
  size == 0 ? 0 : sum(n) / num(n)
end

#nil_percent(n = MAX) ⇒ Object



34
35
36
# File 'lib/pong.rb', line 34

def nil_percent(n = MAX)
  (nils(n).to_f / num(n).to_f) * 100.0
end

#nils(n = MAX) ⇒ Object



30
31
32
# File 'lib/pong.rb', line 30

def nils(n = MAX)
  last(n).select{|value| value.nil? }.size
end

#num(n) ⇒ Object



10
11
12
13
# File 'lib/pong.rb', line 10

def num(n)
  n = MAX if n.nil?
  [n, size].min
end

#sum(n = MAX) ⇒ Object



20
21
22
23
24
# File 'lib/pong.rb', line 20

def sum(n = MAX)
  last(n).inject(0){|memo, value|
    value.nil? ? memo : (memo + value)
  }
end