diff --git a/lib/oga/xml/element.rb b/lib/oga/xml/element.rb index 0d8375c..10b30f2 100644 --- a/lib/oga/xml/element.rb +++ b/lib/oga/xml/element.rb @@ -41,7 +41,7 @@ module Oga # @return [String] # def attribute(name) - return attributes[name] + return attributes[name.to_sym] end alias_method :attr, :attribute diff --git a/lib/oga/xml/parser.y b/lib/oga/xml/parser.y index cfad791..84733e4 100644 --- a/lib/oga/xml/parser.y +++ b/lib/oga/xml/parser.y @@ -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 diff --git a/spec/oga/xml/element_spec.rb b/spec/oga/xml/element_spec.rb index 106253c..3515547 100644 --- a/spec/oga/xml/element_spec.rb +++ b/spec/oga/xml/element_spec.rb @@ -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 == '
' diff --git a/spec/oga/xml/parser/elements_spec.rb b/spec/oga/xml/parser/elements_spec.rb index 28e68c9..a8a698c 100644 --- a/spec/oga/xml/parser/elements_spec.rb +++ b/spec/oga/xml/parser/elements_spec.rb @@ -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 diff --git a/spec/oga/xml/parser/html_void_elements_spec.rb b/spec/oga/xml/parser/html_void_elements_spec.rb index 013b82c..34a081a 100644 --- a/spec/oga/xml/parser/html_void_elements_spec.rb +++ b/spec/oga/xml/parser/html_void_elements_spec.rb @@ -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