rind 0.1.2 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/CHANGELOG.rdoc CHANGED
@@ -1,3 +1,10 @@
1
+ == 0.1.3 - 2010.06.20
2
+ * The Xpath function 's' will return an empty Rind::Node rather than +nil+.
3
+ * Processing instructions were not being treated as nodes.
4
+ * DocType nodes were lacking proper equality checks.
5
+ * The +next+, +next_sibling+, +prev+ and +prev_sibling+ functions were not returning the correct nodes when other available nodes matched <tt>==</tt>.
6
+ * Adding +exact_index+ function to Rind::Nodes. (used in previous bug fix)
7
+
1
8
  == 0.1.2 - 2010.06.17
2
9
  * When parsing HTML, script and style tags will not break because of a "<" in their content.
3
10
  * Tag names can now have numbers. Previously heading tags would not parse correctly.
data/lib/rind/nodes.rb CHANGED
@@ -1,12 +1,20 @@
1
1
  module Rind
2
2
  class Nodes < Array
3
+ # Returns the index of the first object in +self+ such that it is equal? to the node.
4
+ def exact_index(node)
5
+ self.each_index do |index|
6
+ return index if self[index].equal?(node)
7
+ end
8
+ nil
9
+ end
10
+
3
11
  # Return only the nodes that match the Xpath provided.
4
12
  def filter(path)
5
13
  # if the path doesn't have an axis then default to "self"
6
14
  if path !~ /^([.\/]|(.+?::))/
7
15
  path = "self::#{path}"
8
16
  end
9
- Nodes.new(self.find_all{|node| node.s(path)})
17
+ Nodes.new(self.find_all{|node| not node.s(path).empty?})
10
18
  end
11
19
  end
12
20
 
@@ -45,6 +53,8 @@ module Rind
45
53
  end
46
54
 
47
55
  class DocType
56
+ include Equality
57
+
48
58
  # Create a Document Type Declaration with
49
59
  # +content+ holding the DTD identifiers.
50
60
  def initialize(content)
@@ -57,6 +67,11 @@ module Rind
57
67
  end
58
68
 
59
69
  class ProcessingInstruction
70
+ include Equality
71
+ include Manipulate
72
+ include Traverse
73
+ include Xpath
74
+
60
75
  # Create a processing instruction with
61
76
  # +content+ holding the character data.
62
77
  def initialize(content)
data/lib/rind/traverse.rb CHANGED
@@ -49,7 +49,7 @@ module Traverse
49
49
  # it will only return the nodes that match.
50
50
  def next_siblings(path = nil)
51
51
  children = self.parent.children
52
- siblings = Rind::Nodes.new(children[children.index(self)+1..children.length-1])
52
+ siblings = Rind::Nodes.new(children[children.exact_index(self)+1..children.length-1])
53
53
  path.nil? ? siblings : siblings.filter(path)
54
54
  end
55
55
 
@@ -66,7 +66,7 @@ module Traverse
66
66
  # it will only return the nodes that match.
67
67
  def prev_siblings(path = nil)
68
68
  children = self.parent.children
69
- siblings = Rind::Nodes.new(children[0...children.index(self)])
69
+ siblings = Rind::Nodes.new(children[0...children.exact_index(self)])
70
70
  path.nil? ? siblings : siblings.filter(path)
71
71
  end
72
72
 
data/lib/rind/xpath.rb CHANGED
@@ -56,7 +56,7 @@ module Xpath
56
56
  end
57
57
  end
58
58
 
59
- return nil if nodes.empty?
59
+ return Rind::Nodes.new if nodes.empty?
60
60
  end
61
61
 
62
62
  Rind::Nodes.new(nodes)
@@ -64,8 +64,7 @@ module Xpath
64
64
 
65
65
  # Xpath search returning only the first matching node in the list.
66
66
  def sf(path)
67
- nodes = self.s(path)
68
- nodes.nil? ? nil : nodes.first
67
+ self.s(path).first
69
68
  end
70
69
 
71
70
  def find_matching_nodes(axis, node_test) # :nodoc:
data/test/nodes_test.rb CHANGED
@@ -10,7 +10,15 @@ class NodesTest < Test::Unit::TestCase
10
10
  @nodes = Rind::Nodes.new([@p_one, @p_two, @br_one, @br_two])
11
11
  end
12
12
 
13
+ def test_exact_index
14
+ foo = Rind::Html::Foo.new
15
+
16
+ assert_equal(@nodes.exact_index(@p_two), 1)
17
+ assert_nil(@nodes.exact_index(foo))
18
+ end
19
+
13
20
  def test_filter
14
21
  assert_equal(@nodes.filter('br'), [@br_one, @br_two])
22
+ assert_equal(@nodes.filter('a'), [])
15
23
  end
16
24
  end
data/test/xpath_test.rb CHANGED
@@ -19,9 +19,12 @@ class XpathTest < Test::Unit::TestCase
19
19
  assert_equal(@p_one.s('br[2]'), [@br_two])
20
20
  assert_equal(@p_one.s('br[position()=1]'), [@br_one])
21
21
  assert_equal(@p_one.s('br[last()]'), [@br_three])
22
+
23
+ assert_equal(@p_one.s('a'), [])
22
24
  end
23
25
 
24
26
  def test_sf
25
27
  assert_same(@p_one.sf('br'), @br_one)
28
+ assert_nil(@p_one.sf('a'))
26
29
  end
27
30
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rind
3
3
  version: !ruby/object:Gem::Version
4
- hash: 31
4
+ hash: 29
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 2
10
- version: 0.1.2
9
+ - 3
10
+ version: 0.1.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Aaron Lasseigne
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-06-17 00:00:00 -05:00
18
+ date: 2010-06-20 00:00:00 -05:00
19
19
  default_executable:
20
20
  dependencies: []
21
21