Created
July 28, 2015 15:22
-
-
Save arthuralvim/c62cdaf253f5f4caee41 to your computer and use it in GitHub Desktop.
Modelo para trabalhar com fluxos e transições.
This file contains hidden or 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 -*- | |
| import inspect | |
| class TransitionObject(object): | |
| """ | |
| TransitionObject: | |
| Uma classe para ajudar nas passagens de transições em fluxos. | |
| """ | |
| def __init__(self): | |
| self.state = 0 | |
| def transition_1(self): | |
| self.state = 1 | |
| def transition_2(self): | |
| self.state = 2 | |
| def transition_3(self): | |
| self.state = 3 | |
| def reverse_transition_1(self): | |
| self.state = 0 | |
| def reverse_transition_2(self): | |
| self.state = 0 | |
| def reverse_transition_22(self): | |
| self.state = 0 | |
| def get_methods(self): | |
| methods = inspect.getmembers(self, predicate=inspect.ismethod) | |
| return map(lambda x: x[0], methods) | |
| def list_transition_methods(self): | |
| methods = self.get_methods() | |
| return filter(lambda x: x.startswith('transition'), methods) | |
| def list_reversible_transitions(self): | |
| methods = self.get_methods() | |
| return filter(lambda x: x.startswith('reverse_transition'), methods) | |
| def check_reversibility(self): | |
| transitions = self.list_transition_methods() | |
| reversions = self.list_reversible_transitions() | |
| tra_rev = [] | |
| for tra in transitions: | |
| try: | |
| rev = next(rev for rev in reversions if tra in rev) | |
| except StopIteration: | |
| rev = None | |
| tra_rev.append((tra, rev, True if rev else False)) | |
| return tra_rev | |
| if __name__ == '__main__': | |
| tra = TransitionObject() | |
| print tra.check_reversibility() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment