def rubygems_download_url(name, version, platform=None, repo='https://rubygems.org/downloads'):
    """
    Return a .gem download URL given a name, version, and optional platform (e.g. java)
    and a base repo URL.

    For example: https://rubygems.org/downloads/mocha-1.7.0.gem
    """
    if not name or not version:
        return
    repo = repo.rstrip('/')
    name = name.strip().strip('/')
    version = version.strip().strip('/')
    version_plat = version
    if platform  and platform != 'ruby':
        version_plat = '{version}-{platform}'.format(**locals())
    return '{repo}/{name}-{version_plat}.gem'.format(**locals())