lib/apricoteatsgorilla.rb in smacks-apricoteatsgorilla-0.2.6 vs lib/apricoteatsgorilla.rb in smacks-apricoteatsgorilla-0.2.7
- old
+ new
@@ -56,11 +56,11 @@
# Creates an XML tag. Expects a block for tag content.
# Defaults to an empty element tag in case no block was supplied.
def tag(name, attributes = {})
return "<#{name} />" unless block_given?
- attr = opt_order(attributes).map { |k, v| sprintf(' xmlns:%s="%s"', k, v) }.to_s
+ attr = opt_order(attributes).map { |k, v| %Q( xmlns:#{k}="#{v}") }.to_s
body = (yield && !yield.empty?) ? yield : ""
"<#{name}#{attr}>" << body << "</#{name}>"
end
private
@@ -76,10 +76,11 @@
key, value = child.name, booleanize(child.children.first.inner_text)
else
key, value = child.name, xml_node_to_hash(child)
end
+ key = remove_namespace(key)
current = this_node[key]
case current
when Array
this_node[key] << value
when nil
@@ -125,9 +126,14 @@
# Helper to remove line breaks and whitespace between XML tags.
def clean_xml(xml)
xml = xml.gsub(/\n+/, "")
xml = xml.gsub(/(>)\s*(<)/, '\1\2')
+ end
+
+ # Helper to remove namespaces from XML tags.
+ def remove_namespace(tag)
+ tag.sub(/.+:(.+)/, '\1')
end
# Helper to convert "true" and "false" strings to boolean values.
# Returns the original string in case it doesn't match "true" or "false".
def booleanize(string)
\ No newline at end of file