Class: Eiwa::ParsesFile

Inherits:
Object
  • Object
show all
Defined in:
lib/eiwa/parses_file.rb

Instance Method Summary collapse

Instance Method Details

#call(filename, type, each_entry_block) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/eiwa/parses_file.rb', line 7

def call(filename, type, each_entry_block)
  if each_entry_block.nil?
    entries = []
    each_entry_block ||= ->(e) { entries << e }
  end

  doc_for(type).new(each_entry_block).tap do |doc|
    Nokogiri::XML::SAX::Parser.new(doc).parse_file(filename) do |ctx|
      ctx.recovery = true
    end
  end

  entries
end