From 49de0e520b8c879111096c00d1c7abba77ea1fee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thayn=C3=A3=20Moretti?= Date: Sun, 30 Aug 2020 12:37:58 -0300 Subject: [PATCH] Reduce code cognitive complexity --- bumblebee_status/modules/core/memory.py | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/bumblebee_status/modules/core/memory.py b/bumblebee_status/modules/core/memory.py index a4015ff..c9ecf44 100644 --- a/bumblebee_status/modules/core/memory.py +++ b/bumblebee_status/modules/core/memory.py @@ -74,15 +74,22 @@ class Module(core.module.Module): # https://bugs.python.org/issue32933 for line in f.readlines(): tmp = re.split(r"[:\s]+", line) - value = int(tmp[1]) - if tmp[2] == "kB": - value = value * 1024 - if tmp[2] == "mB": - value = value * 1024 * 1024 - if tmp[2] == "gB": - value = value * 1024 * 1024 * 1024 + value = self.__parse_value(tmp) + data[tmp[0]] = value return data + def __parse_value(self, data): + value = int(data[1]) + + if data[2] == "kB": + value = value * 1024 + if data[2] == "mB": + value = value * 1024 * 1024 + if data[2] == "gB": + value = value * 1024 * 1024 * 1024 + + return value + # vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4