Ticket #37 (closed enhancement: fixed)

Opened 2 years ago

Last modified 2 years ago

next_node(#)

Reported by: sbeckeriv Owned by: why
Priority: trivial Milestone: 0.5
Component: lib/hpricot Version: 0.4
Keywords: Cc:

Description

I want the 12th next node. @basic.search("b[@class='blackcatheader']")[0].next_node.next_node.next_node.next_node.next_node.next_node.next_node.next_node.next_node.next_node.next_node.next_node or @basic.search("b[@class='blackcatheader']")[0].next_node(12)

Attachments

movie.html (1.0 kB) - added by sbeckeriv 2 years ago.
example html
test_node.rb (1.3 kB) - added by sbeckeriv 2 years ago.
Test file

Change History

Changed 2 years ago by sbeckeriv

example html

Changed 2 years ago by sbeckeriv

Test file

follow-up: ↓ 2   Changed 2 years ago by tec

What about something like (1..12).inject(header) { |node,_| node.next_node } ?

in reply to: ↑ 1   Changed 2 years ago by sbeckeriv

Replying to tec:

What about something like (1..12).inject(header) { |node,_| node.next_node } ?

Is this a suggestion for writing .next_node 12 times or the test code I posted?

Using inject would prevent 0 and negative indexes.

  Changed 2 years ago by why

  • status changed from new to assigned
  • version set to 0.4
  • milestone set to 0.5

Ohh, I like the range idea, too, though. Maybe it could accept an int or a range. Hmm. Negative values would turn next_node into previous_node, though. Confusing.

Probably better to add a nodes_at method which can take any number of int and range combinations.

 #!ruby
 ele.nodes_at(-3..-1, 1..3) # gets three nodes before and three after
 ele.nodes_at(1, 5, 7) # gets three nodes at offsets below the current node
 ele.nodes_at(0, 5..6) # the current node and two others

  Changed 2 years ago by why

  • status changed from assigned to closed
  • resolution set to fixed

Okay, [90] includes both siblings_at and nodes_at.

Note: See TracTickets for help on using tickets.