Skip to content

Commit

Permalink
Added 'heading' member to RowFmt
Browse files Browse the repository at this point in the history
  • Loading branch information
kfsone committed Nov 3, 2014
1 parent 0c9545a commit e74fa9d
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion formatting.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,15 @@ def __init__(self, name, align, width, qualifier=None, pre=None, post=None, key=
self.pre = pre or ''
self.post = post or ''


def str(self):
return '{pre}{title:{align}{width}}{post}'.format(
title=self.name,
align=self.align, width=self.width,
pre=self.pre, post=self.post,
)


def format(self, value):
return '{pre}{value:{align}{width}{qual}}{post}'.format(
value=self.key(value),
Expand Down Expand Up @@ -107,6 +109,7 @@ def __init__(self, prefix=None):
self.columns = []
self.prefix = prefix or ""


def append(self, column, after=None):
columns = self.columns
if after:
Expand All @@ -117,18 +120,25 @@ def append(self, column, after=None):
columns.append(column)
return self


def insert(self, pos, column):
if column is not None:
self.columns.insert(pos, column)


def str(self):
return self.prefix + ' '.join(col.str() for col in self.columns)


def heading(self):
headline = self.str()
return headline, '-' * len(headline)


def format(self, rowData):
return self.prefix + ' '.join(col.format(rowData) for col in self.columns)



if __name__ == '__main__':
rowFmt = RowFormat(). \
append(ColumnFormat("Name", '<', '8', key=lambda row: row['name'])). \
Expand Down

0 comments on commit e74fa9d

Please sign in to comment.