Sha256: 881d339f94f208abf36403773a7856f2bb8fb73e4bb954be0167285b4b39de6b
Contents?: true
Size: 1.42 KB
Versions: 18
Compression:
Stored size: 1.42 KB
Contents
# -*- coding: utf-8 -*- module Wukong module Streamer # # Mix StructRecordizer into any streamer to make it accept a stream of # objects -- the first field in each line is turned into a class and used to # instantiate an object using the remaining fields on that line. # module StructRecordizer # # Turned the first field into a class name, then use the remaining fields # on that line to instantiate the object to process. # def self.recordize rsrc, *fields klass_name, suffix = rsrc.split('-', 2) klass = Wukong.class_from_resource(klass_name) or return # instantiate the class using the remaining fields on that line begin [ klass.new(*fields), suffix ] rescue ArgumentError => e warn "Couldn't instantiate: #{e} (#{[klass, fields].inspect})" return rescue Exception => e raise [e, rsrc, fields].inspect end end # # # def recordize line StructRecordizer.recordize *line.split("\t") unless line.blank? end end # # Processes file as a stream of objects -- the first field in each line is # turned into a class and used to instantiate an object using the remaining # fields on that line. # # See [StructRecordizer] for more. # class StructStreamer < Wukong::Streamer::Base include StructRecordizer end end end
Version data entries
18 entries across 18 versions & 1 rubygems