import fnmatch

from etlt.condition.SimpleCondition import SimpleCondition


class GlobCondition(SimpleCondition):
    """
    A glob condition matches a field in the row against a glob expression.
    """

    # ------------------------------------------------------------------------------------------------------------------
    def match(self, row):
        """
        Returns True if the field matches the glob expression of this simple condition. Returns False otherwise.

        :param dict row: The row.

        :rtype: bool
        """
        return fnmatch.fnmatchcase(row[self._field], self._expression)

    # ------------------------------------------------------------------------------------------------------------------
    @property
    def scheme(self):
        """
        Returns 'glob'.

        :rtype: str
        """
        return 'glob'

# ----------------------------------------------------------------------------------------------------------------------

import fnmatch

from etlt.condition.SimpleCondition import SimpleCondition


class GlobCondition(SimpleCondition):
    """
    A glob condition matches a field in the row against a glob expression.
    """

    # ------------------------------------------------------------------------------------------------------------------
    def match(self, row):
        """
        Returns True if the field matches the glob expression of this simple condition. Returns False otherwise.

        :param dict row: The row.

        :rtype: bool
        """
        return fnmatch.fnmatchcase(row[self._field], self._expression)

    # ------------------------------------------------------------------------------------------------------------------
    @property
    def scheme(self):
        """
        Returns 'glob'.

        :rtype: str
        """
        return 'glob'

# ----------------------------------------------------------------------------------------------------------------------

A glob condition matches a field in the row against a glob expression. # ------------------------------------------------------------------------------------------------------------------ Returns True if the field matches the glob expression of this simple condition. Returns False otherwise.          :param dict row: The row.          :rtype: bool # ------------------------------------------------------------------------------------------------------------------ Returns 'glob'.          :rtype: str # ----------------------------------------------------------------------------------------------------------------------