mirror of
https://github.com/Oreolek/gamebookformat.git
synced 2024-07-01 06:05:11 +03:00
Better API for tags in sections.
This commit is contained in:
parent
3a1f8821c1
commit
a58a237bc1
|
@ -107,7 +107,7 @@ def parse_file_to_book(inputfile, book):
|
||||||
def add_section_to_book(book, name, text, number=None, tags=None):
|
def add_section_to_book(book, name, text, number=None, tags=None):
|
||||||
section = sections.Section(name, text)
|
section = sections.Section(name, text)
|
||||||
if tags:
|
if tags:
|
||||||
section.set_tags(tags)
|
section.add_tags(tags)
|
||||||
book.add(section)
|
book.add(section)
|
||||||
if number:
|
if number:
|
||||||
book.force_section_nr(name, number)
|
book.force_section_nr(name, number)
|
||||||
|
|
|
@ -7,8 +7,11 @@ class Section:
|
||||||
self.text = text
|
self.text = text
|
||||||
self.tags = set()
|
self.tags = set()
|
||||||
|
|
||||||
def set_tags(self, tags):
|
def add_tags(self, tags):
|
||||||
self.tags = set(tags)
|
self.tags.update(set(tags))
|
||||||
|
|
||||||
|
def hastag(self, tag):
|
||||||
|
return tag in self.tags
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "Section(%s, %s, %s)" % (repr(self.name), repr(self.text),
|
return "Section(%s, %s, %s)" % (repr(self.name), repr(self.text),
|
||||||
|
|
|
@ -14,6 +14,17 @@ class TestSection(TestCase):
|
||||||
self.assertEqual(sec.name, "nnn")
|
self.assertEqual(sec.name, "nnn")
|
||||||
self.assertEqual(sec.text, "text")
|
self.assertEqual(sec.text, "text")
|
||||||
|
|
||||||
|
def test_add_tags(self):
|
||||||
|
sec = sections.Section("nnn", "text")
|
||||||
|
sec.add_tags(['a', 'b'])
|
||||||
|
self.assertTrue(sec.hastag('a'))
|
||||||
|
self.assertTrue(sec.hastag('b'))
|
||||||
|
sec.add_tags(['c', 'd'])
|
||||||
|
self.assertTrue(sec.hastag('a'))
|
||||||
|
self.assertTrue(sec.hastag('b'))
|
||||||
|
self.assertTrue(sec.hastag('c'))
|
||||||
|
self.assertTrue(sec.hastag('d'))
|
||||||
|
|
||||||
class TestBook(TestCase):
|
class TestBook(TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
pass
|
pass
|
||||||
|
|
Loading…
Reference in a new issue