Skip to content

Commit

Permalink
Proposal of implementation for parent_jq() tree traversal utility pla…
Browse files Browse the repository at this point in the history
  • Loading branch information
Ssruno committed Jan 22, 2018
1 parent e42b1e9 commit aa3c62d
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/pincers/core/search_context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,18 @@ def last
if elements.last.nil? then nil else wrap_siblings [elements.last] end
end

def parent_jq(_selector=nil)
if _selector
parser = Pincers::CSS::Parser.new _selector
exp = parser.to_xpath(".//parent::")
exp = exp.first if exp.length == 1

search(:xpath => exp)
else
search( :xpath => 'parent::*' )
end
end

def search(_selector=nil, _options={}, &_block)
if _selector.is_a? Hash
_options = _selector
Expand Down

0 comments on commit aa3c62d

Please sign in to comment.