Sha256: 5a0c5159be0f06b8d0afc38d88b30909f6152b4301a6caae51966e6349ff2b22

Contents?: true

Size: 494 Bytes

Versions: 6

Compression:

Stored size: 494 Bytes

Contents

module Kitabu
  class Stream
    attr_accessor :listener, :content
    attr_reader :html

    def initialize(content, listener)
      @content  = content
      @listener = listener
      @html = Nokogiri::HTML.parse(content)
    end

    def parse
      traverse(html)
    end

    def traverse(node)
      node.children.each do |child|
        emit(child)
        traverse(child)
      end
    end

    def emit(node)
      listener.send(:tag, node) if node.name =~ /h[1-6]/
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
kitabu-2.0.0 lib/kitabu/stream.rb
kitabu-1.0.6 lib/kitabu/stream.rb
kitabu-1.0.5 lib/kitabu/stream.rb
kitabu-1.0.4 lib/kitabu/stream.rb
kitabu-1.0.3 lib/kitabu/stream.rb
kitabu-1.0.2 lib/kitabu/stream.rb