Skip to content

Commit

Permalink
Add render method to Info.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ken Kundert authored and Ken Kundert committed May 25, 2020
1 parent 3497b83 commit 6f4edf1
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions inform/inform.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ def strip_colors(cls, text):


# Info class {{{2
class Info(object):
class Info:
"""Generic Class
When instantiated, it converts the provided keyword arguments to attributes.
Expand Down Expand Up @@ -401,6 +401,9 @@ def __getattr__(self, name):
raise AttributeError(name)
return self.__dict__.get(name)

def render(self, template):
return template.format(**self.__dict__)

def __repr__(self):
return render(self)

Expand Down Expand Up @@ -871,8 +874,8 @@ class plural:
>>> f"{plural(2):!agree}"
'agree'
If '#' or '!' are inconvenient, you can change them by passing the *num* and
*invert* arguments to plural().
If '/', '#', or '!' are inconvenient, you can change them by passing the
*slash*, *num* and *invert* arguments to plural().
The original implementation is from Veedrac on Stack Overflow:
http://stackoverflow.com/questions/21872366/plural-string-formatting
Expand Down

0 comments on commit 6f4edf1

Please sign in to comment.