lib/nokogiri/more.rb in mediawiktory-0.0.3 vs lib/nokogiri/more.rb in mediawiktory-0.1.0
- old
+ new
@@ -1,31 +1,31 @@
+# frozen_string_literal: true
+
require 'naught'
+# @private
+# Used only by Generator
module Nokogiri
module More
module NodeChildrenGroups
def children_groups(*selectors)
groups = []
- flat = children.select{|node| selectors.any?{|s| node.matches?(s)}}
- while !flat.empty?
- groups << make_group(flat, selectors)
- end
+ flat = children.select { |node| selectors.any? { |s| node.matches?(s) } }
+ groups << make_group(flat, selectors) until flat.empty?
groups
end
-
- #include NodeOnlyFor
-
+
def each_term
children_groups('dt', 'dd')
end
-
+
private
-
+
def make_group(flat, selectors)
sel = selectors.dup
group = [[]]
- while !flat.empty?
+ until flat.empty?
if flat.first.matches?(sel.first)
group.last << flat.shift
elsif sel.size > 1 && flat.first.matches?(sel[1])
sel.shift
group << []
@@ -41,11 +41,11 @@
NodeNaught = Naught.build do |config|
config.black_hole
# so you can just `at?(selector).tap{|node| ...`
# and never be inside `tap`, if it's not found
- def tap
+ def tap
self
end
end
module NodeQuestMethods
@@ -58,10 +58,10 @@
end
def at_xpath?(selector)
at_xpath(selector) || NodeNaught.new
end
-
+
def find_child?(selector)
find_child(selector) || NodeNaught.new
end
end
end