diff options
author | emkael <emkael@tlen.pl> | 2018-04-06 00:39:02 +0200 |
---|---|---|
committer | emkael <emkael@tlen.pl> | 2018-04-06 00:39:02 +0200 |
commit | 9b8e34179f2dc17cecb290f8573ad3b57e7178c5 (patch) | |
tree | c67ae0fe2abef3165458329e83722e953e462766 /jfr_playoff | |
parent | 570980de47fee1a72cb8ce54d454de496119bbb0 (diff) |
Coalescing nullable DTO properties
Diffstat (limited to 'jfr_playoff')
-rw-r--r-- | jfr_playoff/dto.py | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/jfr_playoff/dto.py b/jfr_playoff/dto.py index a1b3a7f..a88cd2b 100644 --- a/jfr_playoff/dto.py +++ b/jfr_playoff/dto.py @@ -1,11 +1,18 @@ import sys +def coalesce(*arg): + for el in arg: + if el is not None: + return el + return None + + class Team(object): name = '' score = 0.0 def __unicode__(self): - return u'%s (%.1f)' % (self.name, self.score) + return u'%s (%.1f)' % (coalesce(self.name, '<None>'), self.score) def __repr__(self): return unicode(self).encode(sys.stdin.encoding) @@ -23,7 +30,7 @@ class Match(object): def __repr__(self): return (u'#%d (%s) %s [%s]' % ( - self.id, self.link, [unicode(team) for team in self.teams], + self.id, coalesce(self.link, '<None>'), [unicode(team) for team in self.teams], u'finished' if self.running < 0 else ( u'%d boards' % self.running)) ).encode(sys.stdin.encoding) @@ -37,7 +44,7 @@ class Phase(object): def __repr__(self): return u'%s (%s) <%d matches> [%srunning]' % ( - self.title, self.link, + self.title, coalesce(self.link, '<None>'), len(self.matches), '' if self.running else 'not ') __all__ = ('Team', 'Match', 'Phase') |