class BinData::ChoiceArgProcessor

Private Instance Methods

choices_as_hash(choices) click to toggle source
# File lib/bindata/choice.rb, line 135
def choices_as_hash(choices)
  if choices.respond_to?(:to_ary)
    key_array_by_index(choices.to_ary)
  else
    choices
  end
end
ensure_valid_keys(choices) click to toggle source
# File lib/bindata/choice.rb, line 151
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
key_array_by_index(array) click to toggle source
# File lib/bindata/choice.rb, line 143
def key_array_by_index(array)
  result = {}
  array.each_with_index do |el, i|
    result[i] = el unless el.nil?
  end
  result
end