'Returns the best name match of a ranked list of vhosts.
:param list matches: list of dicts containing the vhost, the matching name,
and the numerical rank
:returns: the most matching vhost
:rtype: :class:`~certbot_nginx.obj.VirtualHost`'

def _select_best_name_match(self, matches):

    if (not matches):
        return None
    elif (matches[0]['rank'] in six.moves.range(2, 6)):
        rank = matches[0]['rank']
        wildcards = [x for x in matches if (x['rank'] == rank)]
        return max(wildcards, key=(lambda x: len(x['name'])))['vhost']
    else:
        return matches[0]['vhost']
