Class: Burlap::Node

Inherits:
Object show all
Defined in:
lib/burlap/node.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ Node

name is the element name to go in the <> and value is a string to go in the node



7
8
9
10
11
12
# File 'lib/burlap/node.rb', line 7

def initialize params={}
  params.each do |k,v|
    meffod = :"#{k}="
    send(meffod, v) #if respond_to?(meffod)
  end
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



3
4
5
# File 'lib/burlap/node.rb', line 3

def name
  @name
end

#valueObject

Returns the value of attribute value.



3
4
5
# File 'lib/burlap/node.rb', line 3

def value
  @value
end

Instance Method Details

#to_burlapObject

Packs this object into nokogiri nodes and returns the XML as a string



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/burlap/node.rb', line 15

def to_burlap
  doc = Nokogiri::XML::Document.new
  root = Nokogiri::XML::Node.new(self.name, doc)

  if self.value.to_s == ""
    root.children = self.value.to_s
  else
    root << self.value.to_s
  end

  convert_hex_entities_to_decimal root.to_xml(nokogiri_xml_options)
end