Sha256: d40606518817df1ae891525d7e31b3c2ab2251b31dca05bdb64043b75563b593

Contents?: true

Size: 633 Bytes

Versions: 1

Compression:

Stored size: 633 Bytes

Contents

module Downsampler
  class DownsampledHash < DelegateClass(Hash)
    
    def mean &block
      inject({}) do |initial, (key, value)|
        result = value.dup.extend(EnumerableExt).mean(&block) if value.is_a?(Array)
        initial[key] = result
        initial
      end
    end

    def sum &block
      inject({}) do |initial, (key, value)|
        result = value.dup.extend(EnumerableExt).sum(&block) if value.is_a?(Array)
        initial[key] = result
        initial
      end
    end

    def counts
      inject({}) do |initial, (key, value)|
        initial[key] = values.count
        initial
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
downsampler-0.1.0 lib/downsampler/downsampled_hash.rb