class BinData::ChoiceArgProcessor

def choices_as_hash(choices)

def choices_as_hash(choices)
  if choices.respond_to?(:to_ary)
    key_array_by_index(choices.to_ary)
  else
    choices
  end
end

def ensure_valid_keys(choices)

def ensure_valid_keys(choices)
  if choices.has_key?(nil)
    raise ArgumentError, ":choices hash may not have nil key"
  end
  if choices.keys.detect { |key| key.is_a?(Symbol) and key != :default }
    raise ArgumentError, ":choices hash may not have symbols for keys"
  end
end

def key_array_by_index(array)

def key_array_by_index(array)
  result = {}
  array.each_with_index do |el, i|
    result[i] = el unless el.nil?
  end
  result
end

def sanitize_parameters!(obj_class, params) #:nodoc:

:nodoc:
def sanitize_parameters!(obj_class, params) #:nodoc:
  params.merge!(obj_class.dsl_params)
  if params.needs_sanitizing?(:choices)
    choices = choices_as_hash(params[:choices])
    ensure_valid_keys(choices)
    params[:choices] = params.create_sanitized_choices(choices)
  end
end