Last active
December 18, 2015 19:09
-
-
Save nvbn/5830627 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
from random import randint | |
class Claim(object): | |
STATE_START = 0 | |
STATE_ANALYZE = 1 | |
STATE_PROCESSING = 2 | |
STATE_CLARIFY = 3 | |
STATE_CLOSE = 4 | |
def __init__(self, state=STATE_START): | |
self._state = state | |
@property | |
def state_handler(self): | |
return { | |
self.STATE_START: self.start, | |
self.STATE_ANALYZE: self.analyze, | |
self.STATE_PROCESSING: self.processing, | |
self.STATE_CLARIFY: self.clarify, | |
self.STATE_CLOSE: self.close, | |
}[self._state] | |
def run(self): | |
while self._state is not None: | |
self.state_handler() | |
def start(self): | |
print u'заявка подана' | |
self._state = self.STATE_ANALYZE | |
def analyze(self): | |
print u'анализ заявки' | |
if randint(0, 2) == 2: | |
print u'заявка принята к исполнению' | |
self._state = self.STATE_PROCESSING | |
else: | |
print u'требуется уточнение' | |
self._state = self.STATE_CLARIFY | |
def processing(self): | |
print u'проведены работы по заявке' | |
self._state = self.STATE_CLOSE | |
def clarify(self): | |
if randint(0, 4) == 4: | |
print u'пользователь отказался от заявки' | |
self._state = self.STATE_CLOSE | |
else: | |
print u'уточнение дано' | |
self._state = self.STATE_ANALYZE | |
def close(self): | |
print u'заявка закрыта' | |
self._state = None |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment