Sha256: 926be2d1f61eea1a4c0b2a0e41e2f273093b01a82829556cffdf3df12cd04dd7

Contents?: true

Size: 601 Bytes

Versions: 1

Compression:

Stored size: 601 Bytes

Contents

require 'rubygems'
require 'interpolate'

# min_value => bucket
buckets = {
  0.000 => 1,
  0.500 => 2,
  1.250 => 3,
  7.725 => 4,
  28.85 => 5,
  50.00 => 6,
  127.5 => 7
}

values = [
  -20.2,
  0.234,
  65.24,
  9.234,
  398.4,
  4000
]

# using Interpolate::Points to place values within discrete intervals
bucketizer = Interpolate::Points.new(buckets)
# the blending function will mimic the mathematical floor function
bucketizer.blend_with {|low, high, balance| low }

values.each do |value|
  bucket = bucketizer.at(value).floor
  puts "A value of #{value} falls into bucket #{bucket}"
end



Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
interpolate-0.3.0 examples/buckets.rb