Class: Saxerator::DocumentFragment

Inherits:
Object
  • Object
show all
Includes:
Enumerable, DSL
Defined in:
lib/saxerator/document_fragment.rb

Instance Method Summary collapse

Methods included from DSL

#at_depth, #child_of, #for_tag, #for_tags, #with_attribute, #with_attributes, #within

Constructor Details

#initialize(source, config = nil, latches = []) ⇒ DocumentFragment

Returns a new instance of DocumentFragment.



6
7
8
9
10
# File 'lib/saxerator/document_fragment.rb', line 6

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

Instance Method Details

#each(&block) ⇒ Object



12
13
14
15
16
17
18
19
20
# File 'lib/saxerator/document_fragment.rb', line 12

def each(&block)
  reader = Parser::LatchedAccumulator.new(@config, @latches, block)
  parser = Nokogiri::XML::SAX::Parser.new(reader)

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

  parser.parse(@source)
end