Params:
            reddit (praw.Reddit): Instance of the reddit api.
            name (text): The name of the desired subreddit, user, multireddit,
                etc. In most cases this translates directly from the URL that
                reddit itself uses. This is what users will type in the command
                prompt when they navigate to a new location.
            loader (terminal.loader): Handler for the load screen that will be
                displayed when making http requests.
            order (text): If specified, the order that posts will be sorted in.
                For `top` and `controversial`, you can specify the time frame
                by including a dash, e.g. "top-year". If an order is not
                specified, it will be extracted from the name.
            query (text): Content to search for on the given subreddit or
                user's page.

def from_name(cls, reddit, name, loader, order=None, query=None):
        """
        Params:
            reddit (praw.Reddit): Instance of the reddit api.
            name (text): The name of the desired subreddit, user, multireddit,
                etc. In most cases this translates directly from the URL that
                reddit itself uses. This is what users will type in the command
                prompt when they navigate to a new location.
            loader (terminal.loader): Handler for the load screen that will be
                displayed when making http requests.
            order (text): If specified, the order that posts will be sorted in.
                For `top` and `controversial`, you can specify the time frame
                by including a dash, e.g. "top-year". If an order is not
                specified, it will be extracted from the name.
            query (text): Content to search for on the given subreddit or
                user's page.
        """
        # TODO: This desperately needs to be refactored

        # Strip leading, trailing, and redundant backslashes
        parts = [seg for seg in name.strip(' /').split('/') if seg]

        # Check for the resource type, assume /r/ as the default
        if len(parts) >= 3 and parts[2] == 'm':
            # E.g. /u/civilization_phaze_3/m/multireddit ->
            #    resource_root = "u/civilization_phaze_3/m"
            #    parts = ["multireddit"]
            resource_root, parts = '/'.join(parts[:3]), parts[3:]
        elif len(parts) > 1 and parts[0] in ['r', 'u', 'user', 'domain']:
            # E.g. /u/civilization_phaze_3 ->
            #    resource_root = "u"
            #    parts = ["civilization_phaze_3"]
            #
            # E.g. /r/python/top-week ->
            #    resource_root = "r"
            #    parts = ["python", "top-week"]
            resource_root = parts.pop(0)
        else:
            resource_root = 'r'

        if resource_root == 'user':
            resource_root = 'u'
        elif resource_root.startswith('user/'):
            # Special check for multi-reddit resource roots
            # E.g.
            #     before: resource_root = "user/civilization_phaze_3/m"
            #     After:  resource_root = "u/civilization_phaze_3/m"
            resource_root = 'u' + resource_root[4:]

        # The parts left should be in one of the following forms:
        #    [resource]
        #    [resource, order]
        #    [resource, user_room, order]

        user_rooms = ['overview', 'submitted', 'comments']
        private_user_rooms = ['upvoted', 'downvoted', 'hidden', 'saved']
        user_room = None

        if len(parts) == 1:
            # E.g. /r/python
            #    parts = ["python"]
            #    resource = "python"
            #    resource_order = None
            resource, resource_order = parts[0], None
        elif resource_root == 'u' and len(parts) in [2, 3] \
                and parts[1] in user_rooms + private_user_rooms:
            # E.g. /u/spez/submitted/top ->
            #    parts = ["spez", "submitted", "top"]
            #    resource = "spez"
            #    user_room = "submitted"
            #    resource_order = "top"
            resource, user_room = parts[:2]
            resource_order = parts[2] if len(parts) == 3 else None
        elif len(parts) == 2:
            # E.g. /r/python/top
            #    parts = ["python", "top"]
            #    resource = "python
            #    resource_order = "top"
            resource, resource_order = parts
        else:
            raise InvalidSubreddit('`{}` is an invalid format'.format(name))

        if not resource:
            # Praw does not correctly handle empty strings
            # https://github.com/praw-dev/praw/issues/615
            raise InvalidSubreddit('Subreddit cannot be empty')

        # If the order was explicitly passed in, it will take priority over
        # the order that was extracted from the name
        order = order or resource_order

        display_order = order
        display_name = '/'.join(['', resource_root, resource])
        if user_room and resource_root == 'u':
            display_name += '/' + user_room

        # Split the order from the period E.g. controversial-all, top-hour
        if order and '-' in order:
            order, period = order.split('-', 1)
        else:
            period = None

        if query:
            # The allowed orders for sorting search results are different
            orders = ['relevance', 'top', 'comments', 'new', None]
            period_allowed = ['top', 'comments']
        else:
            orders = ['hot', 'top', 'rising', 'new', 'controversial', 'gilded', None]
            period_allowed = ['top', 'controversial']

        if order not in orders:
            raise InvalidSubreddit('Invalid order `%s`' % order)
        if period not in ['all', 'day', 'hour', 'month', 'week', 'year', None]:
            raise InvalidSubreddit('Invalid period `%s`' % period)
        if period and order not in period_allowed:
            raise InvalidSubreddit(
                '`%s` order does not allow sorting by period' % order)

        # On some objects, praw doesn't allow you to pass arguments for the
        # order and period. Instead you need to call special helper functions
        # such as Multireddit.get_controversial_from_year(). Build the method
        # name here for convenience.
        if period:
            method_alias = 'get_{0}_from_{1}'.format(order, period)
        elif order:
            method_alias = 'get_{0}'.format(order)
        else:
            method_alias = 'get_hot'

        # Here's where we start to build the submission generators
        if query:
            if resource_root == 'u':
                search = '/r/{subreddit}/search'
                author = reddit.user.name if resource == 'me' else resource
                query = 'author:{0} {1}'.format(author, query)
                subreddit = None
            else:
                search = resource_root + '/{subreddit}/search'
                subreddit = None if resource == 'front' else resource

            reddit.config.API_PATHS['search'] = search
            submissions = reddit.search(query, subreddit=subreddit,
                                        sort=order, period=period)

        elif resource_root == 'domain':
            order = order or 'hot'
            submissions = reddit.get_domain_listing(
                resource, sort=order, period=period, limit=None)

        elif resource_root.endswith('/m'):
            redditor = resource_root.split('/')[1]

            if redditor == 'me':
                if not reddit.is_oauth_session():
                    raise exceptions.AccountError('Not logged in')
                else:
                    redditor = reddit.user.name
                    display_name = display_name.replace(
                        '/me/', '/{0}/'.format(redditor))

            multireddit = reddit.get_multireddit(redditor, resource)
            submissions = getattr(multireddit, method_alias)(limit=None)

        elif resource_root == 'u' and resource == 'me':
            if not reddit.is_oauth_session():
                raise exceptions.AccountError('Not logged in')
            else:
                user_room = user_room or 'overview'
                order = order or 'new'
                period = period or 'all'
                method = getattr(reddit.user, 'get_%s' % user_room)
                submissions = method(sort=order, time=period, limit=None)

        elif resource_root == 'u':
            user_room = user_room or 'overview'
            if user_room not in user_rooms:
                # Tried to access a private room like "u/me/hidden" for a
                # different redditor
                raise InvalidSubreddit('Unavailable Resource')
            order = order or 'new'
            period = period or 'all'
            redditor = reddit.get_redditor(resource)
            method = getattr(redditor, 'get_%s' % user_room)
            submissions = method(sort=order, time=period, limit=None)

        elif resource == 'front':
            if order in (None, 'hot'):
                submissions = reddit.get_front_page(limit=None)
            elif period:
                # For the front page, praw makes you send the period as `t`
                # instead of calling reddit.get_hot_from_week()
                method_alias = 'get_{0}'.format(order)
                method = getattr(reddit, method_alias)
                submissions = method(limit=None, params={'t': period})
            else:
                submissions = getattr(reddit, method_alias)(limit=None)

        else:
            subreddit = reddit.get_subreddit(resource)
            submissions = getattr(subreddit, method_alias)(limit=None)

            # For special subreddits like /r/random we want to replace the
            # display name with the one returned by the request.
            display_name = '/r/{0}'.format(subreddit.display_name)

        filter_nsfw = (reddit.user and reddit.user.over_18 is False)

        # We made it!
        return cls(display_name, submissions, loader, order=display_order,
                   query=query, filter_nsfw=filter_nsfw)