Class: Threatinator::Parsers::XML::NodeBuilder
- Inherits:
-
Object
- Object
- Threatinator::Parsers::XML::NodeBuilder
- Defined in:
- lib/threatinator/parsers/xml/node_builder.rb
Instance Method Summary collapse
- #add_attribute(name, value) ⇒ Object
- #add_child(node) ⇒ Object
- #append_text(chars) ⇒ Object
- #build ⇒ Object
-
#initialize(name, attributes) ⇒ NodeBuilder
constructor
A new instance of NodeBuilder.
Constructor Details
#initialize(name, attributes) ⇒ NodeBuilder
Returns a new instance of NodeBuilder.
7 8 9 10 11 12 13 14 15 16 |
# File 'lib/threatinator/parsers/xml/node_builder.rb', line 7 def initialize(name, attributes) @name = name @attributes = {} @children = [] @text = "" unless attributes.empty? attributes.each { |attr| self.add_attribute(attr.localname, attr.value) } end end |
Instance Method Details
#add_attribute(name, value) ⇒ Object
22 23 24 |
# File 'lib/threatinator/parsers/xml/node_builder.rb', line 22 def add_attribute(name, value) @attributes[name.to_sym] = value end |
#add_child(node) ⇒ Object
26 27 28 |
# File 'lib/threatinator/parsers/xml/node_builder.rb', line 26 def add_child(node) @children << node end |
#append_text(chars) ⇒ Object
18 19 20 |
# File 'lib/threatinator/parsers/xml/node_builder.rb', line 18 def append_text(chars) @text << chars end |
#build ⇒ Object
30 31 32 33 34 35 |
# File 'lib/threatinator/parsers/xml/node_builder.rb', line 30 def build Threatinator::Parsers::XML::Node.new(@name, attrs: @attributes, text: @text.strip, children: @children) end |