Removed the node_type method crap.

The logic this was used for now only resides in the pull parser, instead of
being exposed to the public.

This fixes #30.
This commit is contained in:
Yorick Peterse 2014-09-13 15:09:52 +02:00
parent 9ab5c302f7
commit d082822cdc
17 changed files with 26 additions and 94 deletions

View File

@ -1,5 +1,12 @@
# Changelog
## 0.2.0 - Unreleased
The `node_type` method has been removed and its purpose has been moved into
the `XML::PullParser` class itself. This method was solely used by the pull
parser to provide shorthands for node classes. As such it doesn't make sense to
expose this as a method to the outside world as a public method.
## 0.1.1 - 2014-09-13
This release fixes a problem where element attributes were not separated by

View File

@ -9,7 +9,6 @@ require_relative 'oga/oga'
# Oga::XML namespace.
require_relative 'oga/xml/lexer'
require_relative 'oga/xml/parser'
require_relative 'oga/xml/pull_parser'
require_relative 'liboga'
@ -35,6 +34,7 @@ require_relative 'oga/xml/attribute'
require_relative 'oga/xml/element'
require_relative 'oga/xml/node_set'
require_relative 'oga/xml/pull_parser'
require_relative 'oga/html/parser'
require_relative 'oga/xpath/node'

View File

@ -12,13 +12,6 @@ module Oga
def to_xml
return "<![CDATA[#{text}]]>"
end
##
# @return [Symbol]
#
def node_type
return :cdata
end
end # Cdata
end # XML
end # Oga

View File

@ -12,13 +12,6 @@ module Oga
def to_xml
return "<!--#{text}-->"
end
##
# @return [Symbol]
#
def node_type
return :comment
end
end # Comment
end # XML
end # Oga

View File

@ -79,13 +79,6 @@ module Oga
return "Doctype(#{segments.join(' ')})"
end
##
# @return [Symbol]
#
def node_type
return :doctype
end
end # Doctype
end # XML
end # Oga

View File

@ -236,13 +236,6 @@ module Oga
return "Element(#{segments.join(' ')})"
end
##
# @return [Symbol]
#
def node_type
return :element
end
##
# Registers a new namespace for the current element and its child
# elements.

View File

@ -163,13 +163,6 @@ module Oga
node_set.insert(index, other)
end
##
# @return [Symbol]
#
def node_type
return :node
end
end # Element
end # XML
end # Oga

View File

@ -50,6 +50,21 @@ module Oga
:on_proc_ins
]
##
# Returns the shorthands that can be used for various node classes.
#
# @return [Hash]
#
NODE_SHORTHANDS = {
:text => XML::Text,
:node => XML::Node,
:cdata => XML::Cdata,
:element => XML::Element,
:doctype => XML::Doctype,
:comment => XML::Comment,
:xml_declaration => XML::XmlDeclaration
}
##
# @see Oga::XML::Parser#reset
#
@ -89,8 +104,7 @@ module Oga
# Instead of this:
#
# parser.parse do |node|
# if node.node_type == :text \
# and parser.nesting == %w{people person name}
# if node.is_a?(Oga::XML::Text) and parser.nesting == %w{people person name}
# puts node.text
# end
# end
@ -113,7 +127,7 @@ module Oga
# @param [Array] nesting The element name nesting to act upon.
#
def on(type, nesting = [])
if node.node_type == type
if node.is_a?(NODE_SHORTHANDS[type])
if nesting.empty? or nesting == self.nesting
yield
end

View File

@ -5,12 +5,7 @@ module Oga
# have any children, attributes and the likes; just text.
#
class Text < CharacterNode
##
# @return [Symbol]
#
def node_type
return :text
end
end # Text
end # XML
end # Oga

View File

@ -64,13 +64,6 @@ module Oga
return "XmlDeclaration(#{segments.join(' ')})"
end
##
# @return [Symbol]
#
def node_type
return :xml_decl
end
end # XmlDeclaration
end # XML
end # Oga

View File

@ -33,10 +33,4 @@ describe Oga::XML::Cdata do
@instance.inspect.should == 'Cdata("foo")'
end
end
context '#type' do
example 'return the type of the node' do
described_class.new.node_type.should == :cdata
end
end
end

View File

@ -33,10 +33,4 @@ describe Oga::XML::Comment do
@instance.inspect.should == 'Comment("foo")'
end
end
context '#type' do
example 'return the type of the node' do
described_class.new.node_type.should == :comment
end
end
end

View File

@ -71,10 +71,4 @@ Doctype(name: "html" type: "PUBLIC" inline_rules: "<!ELEMENT foo>")
EOF
end
end
context '#type' do
example 'return the type of the node' do
described_class.new.node_type.should == :doctype
end
end
end

View File

@ -324,12 +324,6 @@ describe Oga::XML::Element do
end
end
context '#type' do
example 'return the type of the node' do
described_class.new.node_type.should == :element
end
end
context '#register_namespace' do
before do
@element = described_class.new

View File

@ -10,12 +10,6 @@ describe Oga::XML::Node do
end
end
context '#type' do
example 'return the type of the node' do
described_class.new.node_type.should == :node
end
end
context '#children' do
example 'return an empty set by default' do
described_class.new.children.empty?.should == true

View File

@ -33,10 +33,4 @@ describe Oga::XML::Text do
@instance.inspect.should == 'Text("foo")'
end
end
context '#type' do
example 'return the type of the node' do
described_class.new.node_type.should == :text
end
end
end

View File

@ -54,10 +54,4 @@ XmlDeclaration(version: "1.0" encoding: "UTF-8")
EOF
end
end
context '#type' do
example 'return the type of the node' do
described_class.new.node_type.should == :xml_decl
end
end
end