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:
Yorick Peterse 2014-05-15 01:04:26 +02:00
parent f4b9bbd4ac
commit 723a273e4f
5 changed files with 7 additions and 7 deletions

View File

@ -41,7 +41,7 @@ module Oga
# @return [String] # @return [String]
# #
def attribute(name) def attribute(name)
return attributes[name] return attributes[name.to_sym]
end end
alias_method :attr, :attribute alias_method :attr, :attribute

View File

@ -137,10 +137,10 @@ rule
attribute attribute
# foo # foo
: T_ATTR { {val[0] => nil} } : T_ATTR { {val[0].to_sym => nil} }
# foo="bar" # foo="bar"
| T_ATTR T_STRING { {val[0] => val[1]} } | T_ATTR T_STRING { {val[0].to_sym => val[1]} }
; ;
# XML declarations # XML declarations

View File

@ -20,7 +20,7 @@ describe Oga::XML::Element do
context '#attribute' do context '#attribute' do
before do before do
@instance = described_class.new(:attributes => {'key' => 'value'}) @instance = described_class.new(:attributes => {:key => 'value'})
end end
example 'return an attribute' do example 'return an attribute' do
@ -42,7 +42,7 @@ describe Oga::XML::Element do
example 'include the attributes if present' do example 'include the attributes if present' do
instance = described_class.new( instance = described_class.new(
:name => 'p', :name => 'p',
:attributes => {'key' => 'value'} :attributes => {:key => 'value'}
) )
instance.to_xml.should == '<p key="value"></p>' instance.to_xml.should == '<p key="value"></p>'

View File

@ -43,7 +43,7 @@ describe Oga::XML::Parser do
end end
example 'set the attributes of the element' do example 'set the attributes of the element' do
@element.attributes.should == {'bar' => 'baz'} @element.attributes.should == {:bar => 'baz'}
end end
end end

View File

@ -39,7 +39,7 @@ describe Oga::XML::Parser do
end end
example 'set the attributes' do example 'set the attributes' do
@node.attributes.should == {'href' => 'foo'} @node.attributes.should == {:href => 'foo'}
end end
end end
end end