Sha256: 7ac48a89397eb38797c90b1f4e0769dd76938ae2ec96deded72b65eaedd6ccab

Contents?: true

Size: 1006 Bytes

Versions: 4

Compression:

Stored size: 1006 Bytes

Contents

require 'epub/publication'

module EPUB
  module Searcher
    class Publication
      class << self
        # @todo Use named argument in the future
        def search(package, word, **options)
          new(word).search(package, options)
        end
      end

      def initialize(word)
        @word = word
      end

      # @todo Use named argument in the future
      def search(package, algorithm: :seamless)
        results = []

        spine = package.spine
        spine_step = Result::Step.new(:element, 2, {:name => 'spine', :id => spine.id})
        spine.each_itemref.with_index do |itemref, index|
          itemref_step = Result::Step.new(:itemref, index, {:id => itemref.id})
          XHTML::ALGORITHMS[algorithm].search(Nokogiri.XML(itemref.item.read), @word).each do |sub_result|
            results << Result.new([spine_step, itemref_step] + sub_result.parent_steps, sub_result.start_steps, sub_result.end_steps)
          end
        end

        results
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
epub-parser-0.2.2 lib/epub/searcher/publication.rb
epub-parser-0.2.1 lib/epub/searcher/publication.rb
epub-parser-0.2.0 lib/epub/searcher/publication.rb
epub-parser-0.1.9 lib/epub/searcher/publication.rb