From 0e7f1b20a3c5b3f4b5f0d4ec12df5e562c273c99 Mon Sep 17 00:00:00 2001 From: Jesse Bannon Date: Thu, 21 Sep 2023 00:14:55 -0700 Subject: [PATCH] more funcs --- .../script/functions/boolean_functions.py | 44 +++++++++++++++++++ .../script/functions/numeric_functions.py | 8 ++++ 2 files changed, 52 insertions(+) create mode 100644 src/ytdl_sub/script/functions/boolean_functions.py diff --git a/src/ytdl_sub/script/functions/boolean_functions.py b/src/ytdl_sub/script/functions/boolean_functions.py new file mode 100644 index 00000000..51cf5fb8 --- /dev/null +++ b/src/ytdl_sub/script/functions/boolean_functions.py @@ -0,0 +1,44 @@ +from ytdl_sub.script.types.resolvable import Boolean +from ytdl_sub.script.types.resolvable import Resolvable + + +class BooleanFunctions: + @staticmethod + def bool(value: Resolvable) -> Boolean: + return Boolean(bool(value.value)) + + @staticmethod + def equals(left: Resolvable, right: Resolvable) -> Boolean: + return Boolean(left.value == right.value) + + @staticmethod + def lt(left: Resolvable, right: Resolvable) -> Boolean: + return Boolean(left.value < right.value) + + @staticmethod + def lte(left: Resolvable, right: Resolvable) -> Boolean: + return Boolean(left.value <= right.value) + + @staticmethod + def gt(left: Resolvable, right: Resolvable) -> Boolean: + return Boolean(left.value > right.value) + + @staticmethod + def gte(left: Resolvable, right: Resolvable) -> Boolean: + return Boolean(left.value >= right.value) + + @staticmethod + def and_(left: Boolean, right: Boolean) -> Boolean: + return Boolean(left.value and right.value) + + @staticmethod + def or_(left: Boolean, right: Boolean) -> Boolean: + return Boolean(left.value or right.value) + + @staticmethod + def xor(left: Boolean, right: Boolean) -> Boolean: + return Boolean(left.value ^ right.value) + + @staticmethod + def not_(value: Boolean) -> Boolean: + return Boolean(not value.value) diff --git a/src/ytdl_sub/script/functions/numeric_functions.py b/src/ytdl_sub/script/functions/numeric_functions.py index beee8c25..2ded52da 100644 --- a/src/ytdl_sub/script/functions/numeric_functions.py +++ b/src/ytdl_sub/script/functions/numeric_functions.py @@ -38,3 +38,11 @@ class NumericFunctions: @staticmethod def mod(value: Integer, modulo: Integer) -> Integer: return Integer(value=value.value % modulo.value) + + @staticmethod + def max(left: Numeric, right: Numeric) -> Numeric: + return _to_numeric(max(left.value, right.value)) + + @staticmethod + def min(left: Numeric, right: Numeric) -> Numeric: + return _to_numeric(min(left.value, right.value))