def cast_to_boolean(value):
    """
    Cast a string to a boolean. Raise a TypeError exception if the
    given value cannot be casted.

    Case insensitive.

    """
    value = value.lower()
    boolean_states = {'true': True, 'false': False}
    if value in boolean_states:
        return boolean_states[value]
    raise TypeError
