Module: Apportion::Setup

Included in:
Apportion
Defined in:
lib/apportion/setup.rb

Overview

Configure per options

Class Method Summary collapse

Class Method Details

.initial_portions(keys, options) ⇒ Hash

Determines initial portions for recipients according to optional constraints

Examples:

initial_portions({a: 41, b: 32, c: 27}, required_minimum: 2)
# => {a: 2, b: 2, c: 2}

Parameters:

  • keys (Hash)

    correspond to recipients

  • options (Hash)
  • options (Hash)

    :prior_portions from a previous apportionment

Options Hash (options):

  • :required_minimum (Integer)

    smallest portion for each recipient

Returns:

  • (Hash)

    portions


19
20
21
22
23
24
25
26
# File 'lib/apportion/setup.rb', line 19

def initial_portions(keys, options)
  portions = Hash.new
  int = options[:required_minimum] || 0
  keys.each { |k| portions[k] = int }
  hash = options[:prior_portions]
  return portions unless hash
  prior_portions_included(portions, hash)
end

.validate(size, sum_portions) ⇒ Object

Raises:

  • (RuntimeError)

    if size too small


33
34
35
# File 'lib/apportion/setup.rb', line 33

def validate(size, sum_portions)
  fail('Size less than minimum sum_portions') if size < sum_portions
end