Sha256: b672fd742f84e48f100420ae029070dd3b547036ef600e452ef07ade08286736
Contents?: true
Size: 908 Bytes
Versions: 2
Compression:
Stored size: 908 Bytes
Contents
module DocxGenerator class Element def initialize(name, attributes = {}, content = []) @name = name @attributes = attributes @content = content end def add(element) @content << element end def generate output = "" if @content.length != 0 output += "<#{@name}#{generate_attributes}>" @content.each do |element| if element.respond_to?(:generate) output += element.generate else output += element.to_s end end output += "</#{@name}>" else output += "<#{@name}#{generate_attributes} />" end output end alias :to_s :generate private def generate_attributes output = "" @attributes.each do |name, value| output += " #{name}=\"#{value}\"" end output end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
docx_generator-0.0.2 | lib/docx_generator/element.rb |
docx_generator-0.0.1 | lib/docx_generator/element.rb |