lib/import/base.rb in tracksperanto-1.9.9 vs lib/import/base.rb in tracksperanto-2.0.0
- old
+ new
@@ -6,11 +6,12 @@
include Tracksperanto::Casts
include Tracksperanto::BlockInit
include Tracksperanto::ZipTuples
include Tracksperanto::ConstName
- # Every time the importer accumulates a tracker this block will be called
+ # Every time the importer accumulates a tracker this object's #push method will be called.
+ # Can be an array or a more full-featured buffer
attr_accessor :receiver
# Tracksperanto will assign a proc that reports the status of the import to the caller.
# This block is automatically used by report_progress IF the proc is assigned. Should
# the proc be nil, the report_progress method will just pass (so you don't need to check for nil
@@ -65,16 +66,10 @@
# OBSOLETE: do not implement this method in your importer. This is used to accumulate trackers in an array
# and then send it to the caller. Used in tests.
def parse(track_file_io)
@receiver = []
- class << @receiver
- def call(with)
- push(with)
- end
- end
-
stream_parse(track_file_io)
@receiver
end
# The main method of the parser. Will receive an IO handle to the file being imported, and should
@@ -85,8 +80,12 @@
def stream_parse(track_file_io)
end
# When a tracker has been detected completely (all keyframes) call this method with the tracker object as argument
def send_tracker(tracker_obj)
- @receiver.call(tracker_obj) if @receiver
+ if @receiver
+ @receiver.push(tracker_obj)
+ else
+ raise "Tracker received but no @receiver has been set for #{self.inspect}"
+ end
end
end
\ No newline at end of file