import inspect
import re


def xtract(clazz_or_instance):
    """
    Extract class name from class, removing the Service/Controller/Resource ending and adding a plural -s or -ies.
    :param clazz_or_instance: the class object
    :return: the name of the desired collection
    """
    clazz_name = clazz_or_instance.__name__ if inspect.isclass(
        clazz_or_instance) else clazz_or_instance.__class__.__name__
    name = re.split('Service|Controller|Resource', clazz_name)[0]
    if name[-2:] in ['sh', 'ch'] or name[-1:] in ['s', 'x', 'z']:
        name = f'{name}es'
    elif name[-1:] == 'y' and (name[-2:-1] in ["a", "e", "i", "o", "u"] or name[-3:-2] == 'qu'):
        name = f'{name[-1:]}ies'
    else:
        name = f'{name}s'
    return name