Allow removal of element attributes.
This commit is contained in:
parent
104576b4ad
commit
cd86d5d294
|
@ -138,6 +138,20 @@ module Oga
|
|||
end
|
||||
end
|
||||
|
||||
##
|
||||
# Removes an attribute from the element.
|
||||
#
|
||||
# @param [String] name The name (optionally including namespace prefix)
|
||||
# of the attribute to remove.
|
||||
#
|
||||
# @return [Oga::XML::Attribute]
|
||||
#
|
||||
def unset(name)
|
||||
found = attribute(name)
|
||||
|
||||
return attributes.delete(found) if found
|
||||
end
|
||||
|
||||
##
|
||||
# Returns the namespace of the element.
|
||||
#
|
||||
|
|
|
@ -170,6 +170,29 @@ describe Oga::XML::Element do
|
|||
end
|
||||
end
|
||||
|
||||
context '#unset' do
|
||||
before do
|
||||
@element = described_class.new
|
||||
|
||||
@element.register_namespace('x', 'test')
|
||||
|
||||
@element.set('foo', 'bar')
|
||||
@element.set('x:foo', 'bar')
|
||||
end
|
||||
|
||||
example 'remove an attribute by its name' do
|
||||
@element.unset('foo')
|
||||
|
||||
@element.get('foo').should be_nil
|
||||
end
|
||||
|
||||
example 'remove an attribute using a namespace' do
|
||||
@element.unset('x:foo')
|
||||
|
||||
@element.get('x:foo').should be_nil
|
||||
end
|
||||
end
|
||||
|
||||
context '#namespace' do
|
||||
example 'return the namespace' do
|
||||
namespace = Oga::XML::Namespace.new(:name => 'x')
|
||||
|
|
Loading…
Reference in New Issue