Skip to content

Commit

Permalink
Tambahkan representasi string tanpa contoh
Browse files Browse the repository at this point in the history
  • Loading branch information
laymonage committed Apr 17, 2019
1 parent ea20a0b commit eaf9295
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ pip install kbbi

Buat objek `KBBI` baru (contoh: `kata = KBBI('kata kunci')`), lalu manfaatkan
representasi `str`-nya dengan memanggil `str(kata)` atau ambil `dict` hasil
serialisasinya dengan memanggil `kata.serialisasi()`.
serialisasinya dengan memanggil `kata.serialisasi()`. Apabila ingin memanfaatkan
representasi `str`-nya tanpa contoh (jika ada), gunakan `__str__(contoh=False)`.

Untuk lebih jelasnya, lihat contoh berikut.

Expand Down
8 changes: 6 additions & 2 deletions kbbi/kbbi.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
.. moduleauthor:: sage <[email protected]>
"""

from re import sub
from urllib.parse import quote

import requests
Expand Down Expand Up @@ -72,8 +73,11 @@ def serialisasi(self):
self.nama: [entri.serialisasi() for entri in self.entri]
}

def __str__(self):
return '\n\n'.join(str(entri) for entri in self.entri)
def __str__(self, contoh=True):
result = '\n\n'.join(str(entri) for entri in self.entri)
if not contoh:
result = sub(':.*', '', result)
return result

def __repr__(self):
return "<KBBI: {}>".format(self.nama)
Expand Down

0 comments on commit eaf9295

Please sign in to comment.