#!/usr/bin/env python3

import lxml.etree as ET

class RssItem(object):
    """Class for storing an RSS 2.0 item."""

    ELEMENTS = ["title", "link", "description", "author", "category", "comments",
                "enclosure", "guid", "pubDate", "source"]

    def __init__(self):
        """Define available attributes."""
        for element in self.ELEMENTS:
            setattr(self, element, None)
        self.timestamp = None
        self.item = None

    def assemble_item(self):
        """Assemble an RSS 2.0 item."""
        self.item = ET.Element("item")
        for element in self.ELEMENTS:
            attr = getattr(self, element)
            if attr is not None:
                self.item.append(attr)

    def dump_item(self):
        """Dump RSS item XML."""
        if self.item is None:
            self.assemble_item()
        return ET.tostring(self.item).decode("utf-8")