Added expanded_name for Element and Attribute
This commit is contained in:
parent
25e2f57a8d
commit
d408989499
|
@ -27,6 +27,7 @@ require 'oga/xml/html_void_elements'
|
|||
require 'oga/xml/entities'
|
||||
require 'oga/xml/querying'
|
||||
require 'oga/xml/traversal'
|
||||
require 'oga/xml/expanded_name'
|
||||
require 'oga/xml/node'
|
||||
require 'oga/xml/document'
|
||||
require 'oga/xml/character_node'
|
||||
|
|
|
@ -4,6 +4,8 @@ module Oga
|
|||
# Class for storing information about a single XML attribute.
|
||||
#
|
||||
class Attribute
|
||||
include ExpandedName
|
||||
|
||||
# The name of the attribute.
|
||||
# @return [String]
|
||||
attr_accessor :name
|
||||
|
|
|
@ -6,6 +6,7 @@ module Oga
|
|||
#
|
||||
class Element < Node
|
||||
include Querying
|
||||
include ExpandedName
|
||||
|
||||
# @return [String]
|
||||
attr_reader :namespace_name
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
module Oga
|
||||
module XML
|
||||
module ExpandedName
|
||||
##
|
||||
# Returns the expanded name of the current Element or Attribute.
|
||||
#
|
||||
# @return [String]
|
||||
#
|
||||
def expanded_name
|
||||
namespace_name ? "#{namespace_name}:#{name}" : name
|
||||
end
|
||||
end # ExpandedName
|
||||
end # XML
|
||||
end # Oga
|
|
@ -164,4 +164,22 @@ Attribute(name: "a" namespace: Namespace(name: "b" uri: nil) value: "c")
|
|||
EOF
|
||||
end
|
||||
end
|
||||
|
||||
describe '#expanded_name' do
|
||||
describe 'with a namespace' do
|
||||
it 'returns a String' do
|
||||
element = described_class.new(:namespace_name => 'foo', :name => 'bar')
|
||||
|
||||
element.expanded_name.should == 'foo:bar'
|
||||
end
|
||||
end
|
||||
|
||||
describe 'without a namespace' do
|
||||
it 'returns a String' do
|
||||
element = described_class.new(:name => 'bar')
|
||||
|
||||
element.expanded_name.should == 'bar'
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -608,4 +608,22 @@ describe Oga::XML::Element do
|
|||
parent.flush_namespaces_cache
|
||||
end
|
||||
end
|
||||
|
||||
describe '#expanded_name' do
|
||||
describe 'with a namespace' do
|
||||
it 'returns a String' do
|
||||
element = described_class.new(:namespace_name => 'foo', :name => 'bar')
|
||||
|
||||
element.expanded_name.should == 'foo:bar'
|
||||
end
|
||||
end
|
||||
|
||||
describe 'without a namespace' do
|
||||
it 'returns a String' do
|
||||
element = described_class.new(:name => 'bar')
|
||||
|
||||
element.expanded_name.should == 'bar'
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue