Sha256: 44700a2f239aa88b09aa5c5cd52061821a5a4705a69c2063d5719403a4e84c24
Contents?: true
Size: 361 Bytes
Versions: 12
Compression:
Stored size: 361 Bytes
Contents
class DivideByType def self.divide(ratios, amount) return {} if amount == 0 ratios = { :no_division => 1 } if ratios == {} Hash[ ratios.each_key.zip(allocate(amount, ratios.each_value)) ] end private def self.allocate(amount, values) total = values.reduce(:+) amount.allocate( values.map { |amount| amount.to_d/total } ) end end
Version data entries
12 entries across 12 versions & 1 rubygems