Class: DocxGenerator::Element
- Inherits:
-
Object
- Object
- DocxGenerator::Element
- Defined in:
- lib/docx_generator/element.rb
Direct Known Subclasses
Word::Body, Word::Bold, Word::Document, Word::Italics, Word::Paragraph, Word::Run, Word::RunProperties, Word::Text
Instance Method Summary collapse
- #add(element) ⇒ Object
- #generate ⇒ Object (also: #to_s)
-
#initialize(name, attributes = {}, content = []) ⇒ Element
constructor
A new instance of Element.
Constructor Details
#initialize(name, attributes = {}, content = []) ⇒ Element
Returns a new instance of Element.
3 4 5 6 7 |
# File 'lib/docx_generator/element.rb', line 3 def initialize(name, attributes = {}, content = []) @name = name @attributes = attributes @content = content end |
Instance Method Details
#add(element) ⇒ Object
9 10 11 |
# File 'lib/docx_generator/element.rb', line 9 def add(element) @content << element end |
#generate ⇒ Object Also known as: to_s
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/docx_generator/element.rb', line 13 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 |