lib/pupa/processor.rb in pupa-0.0.9 vs lib/pupa/processor.rb in pupa-0.0.10
- old
+ new
@@ -114,20 +114,21 @@
end
# Dumps scraped objects to disk.
#
# @param [Symbol] task_name the name of the scraping task to perform
- # @return [Integer] the number of scraped objects
+ # @return [Hash] the number of scraped objects by type
+ # @raises [Pupa::Errors::DuplicateObjectIdError]
def dump_scraped_objects(task_name)
- count = 0
+ counts = Hash.new(0)
@store.pipelined do
send(task_name).each do |object|
- count += 1 # we don't know the size of the enumeration
+ counts[object._type] += 1
dump_scraped_object(object)
end
end
- count
+ counts
end
# Saves scraped objects to a database.
#
# @raises [TSort::Cyclic] if the dependency graph is cyclic
@@ -369,12 +370,12 @@
end
end
# @param [Object] object an object
def import_object(object)
- id = Persistence.new(object).save
+ inserted, id = Persistence.new(object).save
@report[:import][object._type] ||= Hash.new(0)
- if id == object._id
+ if inserted
@report[:import][object._type][:insert] += 1
else
@report[:import][object._type][:update] += 1
end
id