lib/epub/searcher/xhtml.rb in epub-parser-0.2.7 vs lib/epub/searcher/xhtml.rb in epub-parser-0.2.8

- old
+ new

@@ -8,12 +8,12 @@ class << self # @param element [Nokogiri::XML::Element, Nokogiri::XML::Document] # @param word [String] # @return [Array<Result>] - def search(element, word) - new(element.respond_to?(:root) ? element.root : element).search(word) + def search_text(element, word) + new(element.respond_to?(:root) ? element.root : element).search_text(word) end end # @param word [String] def initialize(element) @@ -21,11 +21,11 @@ end class Restricted < self # @param element [Nokogiri::XML::Element] # @return [Array<Result>] - def search(word, element=nil) + def search_text(word, element=nil) results = [] elem_index = 0 (element || @element).children.each do |child| if child.element? @@ -33,11 +33,11 @@ if child.name == 'img' if Parser::Utils.extract_attribute(child, 'alt').index(word) results << Result.new([child_step], nil, nil) end else - search(word, child).each do |sub_result| + search_text(word, child).each do |sub_result| results << Result.new([child_step] + sub_result.parent_steps, sub_result.start_steps, sub_result.end_steps) end end elem_index += 1 elsif child.text? @@ -60,10 +60,10 @@ def initialize(element) super @indices = nil end - def search(word) + def search_text(word) unless @indices @indices, @content = build_indices(@element) end visit(@indices, @content, word) end