Skip to content

Commit

Permalink
Tweak the documentation on Info class.
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 6f4edf1 commit b0c6888
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
1 change: 1 addition & 0 deletions doc/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ clean:
-rm -rf $(BUILDDIR)/*

html:
(cd ..; ./install)
$(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html
@echo
@echo "Build finished. The HTML pages are in $(BUILDDIR)/html."
Expand Down
22 changes: 19 additions & 3 deletions inform/inform.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,17 +372,21 @@ def strip_colors(cls, text):

# Info class {{{2
class Info:
"""Generic Class
"""Generic Data Structure Class
When instantiated, it converts the provided keyword arguments to attributes.
Unknown attributes evaluate to None.
>>> class Orwell(Info):
... pass
>>> george = Orwell(peace='war', truth='lies')
>>> george = Orwell(peace='war', freedom='slavery', ignorance='strength')
>>> print(str(george))
Orwell(peace='war', truth='lies')
Orwell(
peace='war',
freedom='slavery',
ignorance='strength',
)
>>> george.peace
'war'
Expand All @@ -402,6 +406,18 @@ def __getattr__(self, name):
return self.__dict__.get(name)

def render(self, template):
"""Render class to a string
Args:
template (str):
The template string is returned with any instances of {name}
replaced by the value of the corresponding attribute.
>>> george.render('Peace is {peace}. Freedom is {freedom}. Ignorance is {ignorance}.')
'Peace is war. Freedom is slavery. Ignorance is strength.'
"""

return template.format(**self.__dict__)

def __repr__(self):
Expand Down

0 comments on commit b0c6888

Please sign in to comment.