class DataImp::Parser
Attributes
filename[R]
Public Class Methods
find_parser(type)
click to toggle source
# File lib/data_imp/parser.rb, line 9 def self.find_parser type return self if type.blank? begin const_get type.camelize rescue NameError => e if require_relative "parser/#{type.underscore}" retry end end rescue LoadError => e raise DataImp::NoParser.new(type) end
new(filename=nil)
click to toggle source
# File lib/data_imp/parser.rb, line 5 def initialize filename=nil @filename = filename end
Public Instance Methods
parse(chunk)
click to toggle source
# File lib/data_imp/parser.rb, line 22 def parse chunk chunk # assume chunk is a hash end
process(input) { |hash, index| ... }
click to toggle source
# File lib/data_imp/parser.rb, line 26 def process input, &block index = 1 input.each do |chunk| hash = parse(chunk) yield hash, index index += 1 end end
process_file(&block)
click to toggle source
# File lib/data_imp/parser.rb, line 35 def process_file &block open(filename) do |file| process file, &block end end