diff --git a/doc/changelog.md b/doc/changelog.md index f738791..47f6091 100644 --- a/doc/changelog.md +++ b/doc/changelog.md @@ -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 diff --git a/lib/oga.rb b/lib/oga.rb index aadd7fc..56b8e32 100644 --- a/lib/oga.rb +++ b/lib/oga.rb @@ -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' diff --git a/lib/oga/xml/cdata.rb b/lib/oga/xml/cdata.rb index 055bce2..f830f1c 100644 --- a/lib/oga/xml/cdata.rb +++ b/lib/oga/xml/cdata.rb @@ -12,13 +12,6 @@ module Oga def to_xml return "" end - - ## - # @return [Symbol] - # - def node_type - return :cdata - end end # Cdata end # XML end # Oga diff --git a/lib/oga/xml/comment.rb b/lib/oga/xml/comment.rb index 472c7ff..c1f237b 100644 --- a/lib/oga/xml/comment.rb +++ b/lib/oga/xml/comment.rb @@ -12,13 +12,6 @@ module Oga def to_xml return "" end - - ## - # @return [Symbol] - # - def node_type - return :comment - end end # Comment end # XML end # Oga diff --git a/lib/oga/xml/doctype.rb b/lib/oga/xml/doctype.rb index 41a681d..419c2ac 100644 --- a/lib/oga/xml/doctype.rb +++ b/lib/oga/xml/doctype.rb @@ -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 diff --git a/lib/oga/xml/element.rb b/lib/oga/xml/element.rb index 8980fc2..cb328f9 100644 --- a/lib/oga/xml/element.rb +++ b/lib/oga/xml/element.rb @@ -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. diff --git a/lib/oga/xml/node.rb b/lib/oga/xml/node.rb index 5ddfc90..817399c 100644 --- a/lib/oga/xml/node.rb +++ b/lib/oga/xml/node.rb @@ -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 diff --git a/lib/oga/xml/pull_parser.rb b/lib/oga/xml/pull_parser.rb index 0bc632b..c2242bd 100644 --- a/lib/oga/xml/pull_parser.rb +++ b/lib/oga/xml/pull_parser.rb @@ -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 diff --git a/lib/oga/xml/text.rb b/lib/oga/xml/text.rb index 5560acd..b7d4dcf 100644 --- a/lib/oga/xml/text.rb +++ b/lib/oga/xml/text.rb @@ -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 diff --git a/lib/oga/xml/xml_declaration.rb b/lib/oga/xml/xml_declaration.rb index 93fe19e..4130548 100644 --- a/lib/oga/xml/xml_declaration.rb +++ b/lib/oga/xml/xml_declaration.rb @@ -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 diff --git a/spec/oga/xml/cdata_spec.rb b/spec/oga/xml/cdata_spec.rb index 916b2b4..3d54cd7 100644 --- a/spec/oga/xml/cdata_spec.rb +++ b/spec/oga/xml/cdata_spec.rb @@ -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 diff --git a/spec/oga/xml/comment_spec.rb b/spec/oga/xml/comment_spec.rb index 9a07513..8a2418a 100644 --- a/spec/oga/xml/comment_spec.rb +++ b/spec/oga/xml/comment_spec.rb @@ -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 diff --git a/spec/oga/xml/doctype_spec.rb b/spec/oga/xml/doctype_spec.rb index 8be3be2..a316335 100644 --- a/spec/oga/xml/doctype_spec.rb +++ b/spec/oga/xml/doctype_spec.rb @@ -71,10 +71,4 @@ Doctype(name: "html" type: "PUBLIC" inline_rules: "") EOF end end - - context '#type' do - example 'return the type of the node' do - described_class.new.node_type.should == :doctype - end - end end diff --git a/spec/oga/xml/element_spec.rb b/spec/oga/xml/element_spec.rb index 88d8716..41179b2 100644 --- a/spec/oga/xml/element_spec.rb +++ b/spec/oga/xml/element_spec.rb @@ -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 diff --git a/spec/oga/xml/node_spec.rb b/spec/oga/xml/node_spec.rb index a568343..7b519a3 100644 --- a/spec/oga/xml/node_spec.rb +++ b/spec/oga/xml/node_spec.rb @@ -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 diff --git a/spec/oga/xml/text_spec.rb b/spec/oga/xml/text_spec.rb index d8e1671..6fd2728 100644 --- a/spec/oga/xml/text_spec.rb +++ b/spec/oga/xml/text_spec.rb @@ -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 diff --git a/spec/oga/xml/xml_declaration_spec.rb b/spec/oga/xml/xml_declaration_spec.rb index 743dcd1..13f2b05 100644 --- a/spec/oga/xml/xml_declaration_spec.rb +++ b/spec/oga/xml/xml_declaration_spec.rb @@ -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