Enforce symbols for element attributes.
This comes with a little bit of memory overhead but this should be minor in most cases.
This commit is contained in:
parent
f4b9bbd4ac
commit
723a273e4f
|
@ -41,7 +41,7 @@ module Oga
|
|||
# @return [String]
|
||||
#
|
||||
def attribute(name)
|
||||
return attributes[name]
|
||||
return attributes[name.to_sym]
|
||||
end
|
||||
|
||||
alias_method :attr, :attribute
|
||||
|
|
|
@ -137,10 +137,10 @@ rule
|
|||
|
||||
attribute
|
||||
# foo
|
||||
: T_ATTR { {val[0] => nil} }
|
||||
: T_ATTR { {val[0].to_sym => nil} }
|
||||
|
||||
# foo="bar"
|
||||
| T_ATTR T_STRING { {val[0] => val[1]} }
|
||||
| T_ATTR T_STRING { {val[0].to_sym => val[1]} }
|
||||
;
|
||||
|
||||
# XML declarations
|
||||
|
|
|
@ -20,7 +20,7 @@ describe Oga::XML::Element do
|
|||
|
||||
context '#attribute' do
|
||||
before do
|
||||
@instance = described_class.new(:attributes => {'key' => 'value'})
|
||||
@instance = described_class.new(:attributes => {:key => 'value'})
|
||||
end
|
||||
|
||||
example 'return an attribute' do
|
||||
|
@ -42,7 +42,7 @@ describe Oga::XML::Element do
|
|||
example 'include the attributes if present' do
|
||||
instance = described_class.new(
|
||||
:name => 'p',
|
||||
:attributes => {'key' => 'value'}
|
||||
:attributes => {:key => 'value'}
|
||||
)
|
||||
|
||||
instance.to_xml.should == '<p key="value"></p>'
|
||||
|
|
|
@ -43,7 +43,7 @@ describe Oga::XML::Parser do
|
|||
end
|
||||
|
||||
example 'set the attributes of the element' do
|
||||
@element.attributes.should == {'bar' => 'baz'}
|
||||
@element.attributes.should == {:bar => 'baz'}
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -39,7 +39,7 @@ describe Oga::XML::Parser do
|
|||
end
|
||||
|
||||
example 'set the attributes' do
|
||||
@node.attributes.should == {'href' => 'foo'}
|
||||
@node.attributes.should == {:href => 'foo'}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue