Sha256: 3d7f3ce9f2977ec78fd9ef296dceb6ce155aced6566e2ef91494e342a50d2882

Contents?: true

Size: 487 Bytes

Versions: 3

Compression:

Stored size: 487 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.tag(node) if node.name =~ /h[1-6]/
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
kitabu-2.0.3 lib/kitabu/stream.rb
kitabu-2.0.2 lib/kitabu/stream.rb
kitabu-2.0.1 lib/kitabu/stream.rb