From 4aaaabb306e869e814d36737d1123f77045ba02c Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Sun, 19 Jun 2016 00:15:04 +0300 Subject: factor things out of vk.user --- vk/platform.py | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 vk/platform.py (limited to 'vk/platform.py') diff --git a/vk/platform.py b/vk/platform.py new file mode 100644 index 0000000..4a9d8b6 --- /dev/null +++ b/vk/platform.py @@ -0,0 +1,50 @@ +# Copyright 2016 Egor Tensin +# This file is licensed under the terms of the MIT License. +# See LICENSE.txt for details. + +from enum import Enum +import re + +class Platform(Enum): + MOBILE = 1 + IPHONE = 2 + IPAD = 3 + ANDROID = 4 + WINDOWS_PHONE = 5 + WINDOWS8 = 6 + WEB = 7 + + @staticmethod + def from_string(s): + return Platform(int(s)) + + def __str__(self): + return str(self.value) + + @staticmethod + def _uppercase_first_letter(s): + m = re.search(r'\w', s) + if m is None: + return s + return s[:m.start()] + m.group().upper() + s[m.end():] + + def get_description_for_header(self): + return self._uppercase_first_letter(_PLATFORM_DESCRIPTIONS[self]) + + def get_description_for_sentence(self): + s = _PLATFORM_DESCRIPTIONS[self] + s = s.replace('unrecognized', 'an unrecognized') + return 'the ' + s + + def get_description_for_sentence_beginning(self): + return self._uppercase_first_letter(self.get_description_for_sentence()) + +_PLATFORM_DESCRIPTIONS = { + Platform.MOBILE: '"mobile" web version (or unrecognized mobile app)', + Platform.IPHONE: 'official iPhone app', + Platform.IPAD: 'official iPad app', + Platform.ANDROID: 'official Android app', + Platform.WINDOWS_PHONE: 'official Windows Phone app', + Platform.WINDOWS8: 'official Windows 8 app', + Platform.WEB: 'web version (or unrecognized app)' +} -- cgit v1.2.3