#!./python_link
# -*- coding: utf-8 -*-
################################################################################
#    DChars-FE Copyright (C) 2008 Xavier Faure
#    Contact: faure dot epistulam dot mihi dot scripsisti at orange dot fr
#
#    This file is part of DChars-FE.
#    DChars-FE is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#
#    DChars-FE is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with DChars-FE.  If not, see <http://www.gnu.org/licenses/>.
################################################################################
"""
        ❏DChars-FE❏ direction.py

        ***************
        * format @003 *
        ***************
        values for Transformation.direction :
        0 (unset), 1(text -> transliteration), -1(transliteration -> text)
"""

from errors.errors import DCharsFEError

################################################################################
class Direction(object):
    """
        class Direction

        Simple wrapper around the int(eger) value of the direction.
    """

    unset = 0
    text_to_transliterated_text = +1
    transliterated_text_to_text = -1

    #///////////////////////////////////////////////////////////////////////////
    def __init__(self, value = None):
        """
                Direction.__init__
        """

        if value == Direction.unset or value is None:
            self.value = Direction.unset

        elif value == Direction.text_to_transliterated_text:
            self.value = Direction.text_to_transliterated_text

        elif value == Direction.transliterated_text_to_text:
            self.value = Direction.transliterated_text_to_text

        elif value == "unset":
            self.value = Direction.unset

        elif value == "text -> transliteration":
            self.value = Direction.text_to_transliterated_text

        elif value == "transliteration -> text":
            self.value = Direction.transliterated_text_to_text

        else:
            raise DCharsFEError( context = "Direction.__init__",
                                 message = "unknown value = " + str(value) )

    #///////////////////////////////////////////////////////////////////////////
    def GetCorrespondingStr(self):
        """
                Direction.GetCorrespondingStr
        """

        if self.value == Direction.unset:
            return "unset"

        elif self.value == Direction.text_to_transliterated_text:
            return "text -> transliteration"

        elif self.value == Direction.transliterated_text_to_text:
            return "transliteration -> text"

    #///////////////////////////////////////////////////////////////////////////
    def has_been_set(self):
        """
                Direction has_been_set

                Return either True if <self> is initialized, either False
        """
        return self.value != Direction.unset

        
