Module: BinCounter

Extended by:
BinCounter
Included in:
BinCounter
Defined in:
lib/histogram/bin_counter.rb

Instance Method Summary collapse

Instance Method Details

#evaluate(values) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/histogram/bin_counter.rb', line 6

def evaluate(values)
  min, max = values.minmax

  candidate =
    if max - min <= 12 && (max.integer? || min.integer?)
      (max - min).ceil
    elsif max - min <= 1
      10
    elsif max - min <= 12
      12
    elsif Math.sqrt(max - min) <= 12
      Math.sqrt(max - min).ceil
    end

  candidate || [Math.sqrt(values.size).ceil, 12].min
end