public function write($directory = null)
    {
        $file = $this->getFilename();

        if ($directory === null) {
            $directory = dirname($file);
            $file = basename($file);
        }

        $file = $directory . DIRECTORY_SEPARATOR . $file;
        if (is_writable($directory) !== true) {
            throw new RuntimeException('The file "' . $file . '" is not writable.');
        }

        file_put_contents($file, $this->generate());

        return $this;
    }