lib/rspreadsheet/tools.rb in rspreadsheet-0.2.7 vs lib/rspreadsheet/tools.rb in rspreadsheet-0.2.9
- old
+ new
@@ -128,10 +128,11 @@
end
return @ns[prefix]
end
# sets namespaced attribute "ns_prefix:key" in node to value. if value == delete_value then remove the attribute
def self.set_ns_attribute(node,ns_prefix,key,value,delete_value=nil)
+ raise 'Tools.set_ns_attribute can not set attribute on nil node' if node.nil?
ns = Tools.get_namespace(ns_prefix)
attr = node.attributes.get_attribute_ns(ns.href, key)
unless value==delete_value # set attribute
if attr.nil? # create attribute if needed
@@ -150,11 +151,15 @@
node.attributes.get_attribute_ns(Tools.get_namespace(ns_prefix).href,key)
else
node.nil? ? default : node.attributes.get_attribute_ns(Tools.get_namespace(ns_prefix).href,key) || default
end
end
- def self.get_ns_attribute_value(node,ns_prefix,key)
- Tools.get_ns_attribute(node,ns_prefix,key).andand.value
+ def self.get_ns_attribute_value(node,ns_prefix,key,default=:undefined_default)
+ if default==:undefined_default
+ Tools.get_ns_attribute(node,ns_prefix,key).andand.value
+ else
+ node.nil? ? default : Tools.get_ns_attribute(node,ns_prefix,key,nil).andand.value || default
+ end
end
def self.remove_ns_attribute(node,ns_prefix,key)
node.attributes.get_attribute_ns(Tools.get_namespace(ns_prefix).href,key)
attr.remove! unless attr.nil?
end
\ No newline at end of file