soulcutter/saxerator

View on GitHub
lib/saxerator/document_fragment.rb

Summary

Maintainability
A
0 mins
Test Coverage
module Saxerator
  class DocumentFragment
    include Enumerable
    include DSL

    def initialize(source, config = nil, latches = [])
      @source = source
      @latches = latches
      @config = config
    end

    def each(&block)
      return to_enum unless block_given?

      # Always have to start at the beginning of a File
      @source.rewind if @source.respond_to?(:rewind)

      reader = Parser::LatchedAccumulator.new(@config, @latches, block)
      @config.adapter.parse(@source, reader)
    end
  end
end