Sha256: c6a00bd956fbd452fc3160eef5b3c98eb38e0e80fe5345bbde5b39b7f3dfabf5

Contents?: true

Size: 671 Bytes

Versions: 4

Compression:

Stored size: 671 Bytes

Contents

require 'simple_stats/core_ext/enumerable'

module Enumerable
  alias frequencies_orig frequencies

  def frequencies(interval = nil, &block)
    if interval
      fs0 = self.map {|i| i - i % interval }.frequencies(&block)
      fs = {}

      (fs0.keys.min..fs0.keys.max).step(interval).each do |n|
        fs[n] = fs0[n] || 0
      end

      fs
    else
      frequencies_orig(&block)
    end
  end

  def to_gruff_labels
    labels = {}

    self.each_with_index do |label, i|
      labels[i] = label
    end

    if block_given?
      labels = Hash[*labels.select {|k, v| yield(k, v) }.flatten]
    end

    Hash[*labels.map {|k, v| [k, v.to_s] }.flatten]
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
jtl-0.1.5 lib/jtl/core_ext/enumerable.rb
jtl-0.1.4 lib/jtl/core_ext/enumerable.rb
jtl-0.1.3 lib/jtl/core_ext/enumerable.rb
jtl-0.1.2 lib/jtl/core_ext/enumerable.rb