class DivideByType
Public Class Methods
divide(ratios, amount)
click to toggle source
# File lib/guerrilla_patch/aggregate_by_type/divide_by_type.rb, line 2 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 Class Methods
allocate(amount, values)
click to toggle source
# File lib/guerrilla_patch/aggregate_by_type/divide_by_type.rb, line 10 def self.allocate(amount, values) total = values.reduce(:+) amount.allocate( values.map { |amount| amount.to_d/total } ) end