Sha256: 49b176a3134c542daf1dbdf2c4bc2b633b5f807d25de1967451ecd65a77ca9c6

Contents?: true

Size: 521 Bytes

Versions: 9

Compression:

Stored size: 521 Bytes

Contents

require 'enumerator'

# Set of basic array math functions.  
module ArrayMath

  def aaverage
    accum = self.asum
    return nil if accum.nil? || self.size == 0
    accum.to_f / self.size
  end

  def asum
    self.map {|i| return nil if i.is_a?(String)}
    inject(0){ |sum,item| sum + item }
  end
  
  ## Retun array FACTOR smaller.  Average values to get smaller
  def smoothed(factor)
    self.enum_for(:each_slice, factor).map { |snipit| snipit.compact.aaverage }
  end  
end

class Array
  include ArrayMath
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
teich-hrmparser-0.2.1 lib/hrmparser/arraymath.rb
teich-hrmparser-0.2.2 lib/hrmparser/arraymath.rb
teich-hrmparser-0.3.0 lib/hrmparser/arraymath.rb
teich-hrmparser-0.3.1 lib/hrmparser/arraymath.rb
teich-hrmparser-0.4.0 lib/hrmparser/arraymath.rb
teich-hrmparser-0.4.1 lib/hrmparser/arraymath.rb
teich-hrmparser-0.4.2 lib/hrmparser/arraymath.rb
teich-hrmparser-0.4.3 lib/hrmparser/arraymath.rb
teich-hrmparser-0.4.4 lib/hrmparser/arraymath.rb