<commit_before>from enum import Enum, unique
from typing import Optional, Union, cast

from dataproperty import Align
from tcolorpy import Color

from .._function import normalize_enum
from ._font import FontSize, FontStyle, FontWeight


@unique
class ThousandSeparator(Enum):
    NONE = "none"
    COMMA = "comma"
    SPACE = "space"
    UNDERSCORE = "underscore"


@unique
class VerticalAlign(Enum):
    BASELINE = (1 << 0, "baseline")
    TOP = (1 << 1, "top")
    MIDDLE = (1 << 2, "middle")
    BOTTOM = (1 << 3, "bottom")

    @property
    def align_code(self):
        return self.__align_code

    @property
    def align_str(self):
        return self.__align_string

    def __init__(self, code, string):
        self.__align_code = code
        self.__align_string = string


_s_to_ts = {
    "": ThousandSeparator.NONE,
    ",": ThousandSeparator.COMMA,
    " ": ThousandSeparator.SPACE,
    "_": ThousandSeparator.UNDERSCORE,
}


def _normalize_thousand_separator(value: Union[str, ThousandSeparator]) -> ThousandSeparator:
    if isinstance(value, ThousandSeparator):
        return value

    norm_value = _s_to_ts.get(value)
    if norm_value is None:
        return cast(ThousandSeparator, value)

    return norm_value


class Style:
    """Style specifier class for table elements.

    Args:
        color (Optional[Color]):
            text color for cells.
            Only applicable for part of text format writer classes.

        bg_color (Optional[Color]):
            background color for cells.
            Only applicable for part of text format writer classes.

        align (|str| / :py:class:`~.style.Align`):
            Horizontal text alignment for cells.
            This can be only applied for text format writer classes.
            Possible string values are:

            - ``"auto"`` (default)
                - Detect data type for each column and set alignment that appropriate
                  for the type automatically
            - ``"left"``
            - ``"right"``
            - ``"center"``

        vertical_align (|str| / :py:class:`~.style.VerticalAlign`):
            Vertical text alignment for cells.
            This can be only applied for HtmlTableWriter class.
            Possible string values are:

            - ``"baseline"`` (default)
            - ``"top"``
            - ``"middle"``
            - ``"bottom"``

        font_size (|str| / :py:class:`~.style.FontSize`):
            Font size specification for cells in a column.
            This can be only applied for HTML/Latex writer classes.
            Possible string values are:

            - ``"tiny"``
            - ``"small"``
            - ``"medium"``
            - ``"large"``
            - ``"none"`` (no font size specification)

        font_weight (|str| / :py:class:`~.style.FontWeight`):
            Font weight specification for cells in a column.
            This can be only applied for HTML/Latex/Markdown writer classes.
            Possible string values are:

            - ``"normal"`` (default)
            - ``"bold"``

        font_style (|str| / :py:class:`~.style.FontStyle`):
            Font style specification for cells in a column.
            This can be applied only for HTML/Latex/Markdown writer classes.
            Possible string values are:

            - ``"normal"`` (default)
            - ``"italic"``

        thousand_separator (|str| / :py:class:`~.style.ThousandSeparator`):
            Thousand separator specification for numbers in a column.
            This can be only applied for text format writer classes.
            Possible string values are:

            - ``","``/``"comma"``
            - ``" "``/``"space"``
            - ``"_"``/``"underscore"``
            - ``""``/``"none"`` (default)

    Example:
        :ref:`example-style`
    """

    @property
    def align(self) -> Align:
        return self.__align

    @property
    def vertical_align(self) -> VerticalAlign:
        return self.__valign

    @property
    def font_size(self) -> FontSize:
        return self.__font_size

    @property
    def font_style(self) -> FontStyle:
        return self.__font_style

    @property<commit_msg>Add align setter to Style class<commit_after>from enum import Enum, unique
from typing import Optional, Union, cast

from dataproperty import Align
from tcolorpy import Color

from .._function import normalize_enum
from ._font import FontSize, FontStyle, FontWeight


@unique
class ThousandSeparator(Enum):
    NONE = "none"
    COMMA = "comma"
    SPACE = "space"
    UNDERSCORE = "underscore"


@unique
class VerticalAlign(Enum):
    BASELINE = (1 << 0, "baseline")
    TOP = (1 << 1, "top")
    MIDDLE = (1 << 2, "middle")
    BOTTOM = (1 << 3, "bottom")

    @property
    def align_code(self):
        return self.__align_code

    @property
    def align_str(self):
        return self.__align_string

    def __init__(self, code, string):
        self.__align_code = code
        self.__align_string = string


_s_to_ts = {
    "": ThousandSeparator.NONE,
    ",": ThousandSeparator.COMMA,
    " ": ThousandSeparator.SPACE,
    "_": ThousandSeparator.UNDERSCORE,
}


def _normalize_thousand_separator(value: Union[str, ThousandSeparator]) -> ThousandSeparator:
    if isinstance(value, ThousandSeparator):
        return value

    norm_value = _s_to_ts.get(value)
    if norm_value is None:
        return cast(ThousandSeparator, value)

    return norm_value


class Style:
    """Style specifier class for table elements.

    Args:
        color (Optional[Color]):
            text color for cells.
            Only applicable for part of text format writer classes.

        bg_color (Optional[Color]):
            background color for cells.
            Only applicable for part of text format writer classes.

        align (|str| / :py:class:`~.style.Align`):
            Horizontal text alignment for cells.
            This can be only applied for text format writer classes.
            Possible string values are:

            - ``"auto"`` (default)
                - Detect data type for each column and set alignment that appropriate
                  for the type automatically
            - ``"left"``
            - ``"right"``
            - ``"center"``

        vertical_align (|str| / :py:class:`~.style.VerticalAlign`):
            Vertical text alignment for cells.
            This can be only applied for HtmlTableWriter class.
            Possible string values are:

            - ``"baseline"`` (default)
            - ``"top"``
            - ``"middle"``
            - ``"bottom"``

        font_size (|str| / :py:class:`~.style.FontSize`):
            Font size specification for cells in a column.
            This can be only applied for HTML/Latex writer classes.
            Possible string values are:

            - ``"tiny"``
            - ``"small"``
            - ``"medium"``
            - ``"large"``
            - ``"none"`` (no font size specification)

        font_weight (|str| / :py:class:`~.style.FontWeight`):
            Font weight specification for cells in a column.
            This can be only applied for HTML/Latex/Markdown writer classes.
            Possible string values are:

            - ``"normal"`` (default)
            - ``"bold"``

        font_style (|str| / :py:class:`~.style.FontStyle`):
            Font style specification for cells in a column.
            This can be applied only for HTML/Latex/Markdown writer classes.
            Possible string values are:

            - ``"normal"`` (default)
            - ``"italic"``

        thousand_separator (|str| / :py:class:`~.style.ThousandSeparator`):
            Thousand separator specification for numbers in a column.
            This can be only applied for text format writer classes.
            Possible string values are:

            - ``","``/``"comma"``
            - ``" "``/``"space"``
            - ``"_"``/``"underscore"``
            - ``""``/``"none"`` (default)

    Example:
        :ref:`example-style`
    """

    @property
    def align(self) -> Align:
        return self.__align

    @align.setter
    def align(self, value: Align) -> None:
        self.__align = value

    @property
    def vertical_align(self) -> VerticalAlign:
        return self.__valign

    @property
    def font_size(self) -> FontSize:
        return self.__font_size

    @property
    def font_style(self) -> FontStyle:
        return self.__font_style

    @property
{'fraction_non_alphanumeric': 0.11445712269144806, 'fraction_numerical': 0.0018821315139395365, 'mean_word_length': 2.05607476635514, 'pattern_counts': {'":': 8, '<': 19, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4600085', 'n_tokens_mistral': 2475, 'n_tokens_neox': 2341, 'n_words': 718}