Class: DocxGenerator::Element
- Inherits:
-
Object
- Object
- DocxGenerator::Element
- Defined in:
- lib/docx_generator/element.rb
Overview
Represent an XML element. This class should not be used directly by the users of the library.
Direct Known Subclasses
Word::Alignment, Word::Body, Word::Bold, Word::Break, Word::CapitalLetters, Word::Document, Word::Font, Word::Indentation, Word::Italics, Word::Paragraph, Word::ParagraphProperties, Word::Run, Word::RunProperties, Word::Size, Word::SmallCapitalLetters, Word::Spacing, Word::Tab, Word::Tabs, Word::Text, Word::Underline, Word::VerticalAlign
Instance Method Summary collapse
-
#add(element) ⇒ Object
Add an XML element in the content of this XML element.
-
#generate ⇒ String
(also: #to_s)
Generate the XML for the element.
-
#initialize(name, attributes = {}, content = []) ⇒ Element
constructor
Create a new XML element.
Constructor Details
#initialize(name, attributes = {}, content = []) ⇒ Element
Create a new XML element.
10 11 12 13 14 |
# File 'lib/docx_generator/element.rb', line 10 def initialize(name, attributes = {}, content = []) @name = name @attributes = attributes @content = content end |
Instance Method Details
#add(element) ⇒ Object
Add an XML element in the content of this XML element.
18 19 20 |
# File 'lib/docx_generator/element.rb', line 18 def add(element) @content << element end |
#generate ⇒ String Also known as: to_s
Generate the XML for the element.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/docx_generator/element.rb', line 24 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 |