def find_gem_to_install(gem_name, version_requirement)
specs_n_sources = specs_n_sources_matching gem_name, version_requirement
top_3_versions = specs_n_sources.map{|gs| gs.first.version}.uniq[0..3]
specs_n_sources.reject!{|gs| !top_3_versions.include?(gs.first.version)}
binary_gems = specs_n_sources.reject { |item|
item[0].platform.nil? || item[0].platform==Platform::RUBY
}
return specs_n_sources.first if binary_gems.empty?
list = specs_n_sources.collect { |spec, source_uri|
"#{spec.name} #{spec.version} (#{spec.platform})"
}
list << "Skip this gem"
list << "Cancel installation"
string, index = choose_from_list(
"Select which gem to install for your platform (#{RUBY_PLATFORM})",
list)
if index.nil? or index == (list.size - 1) then
raise RemoteInstallationCancelled, "Installation of #{gem_name} cancelled."
end
if index == (list.size - 2) then
raise RemoteInstallationSkipped, "Installation of #{gem_name} skipped."
end
specs_n_sources[index]
end