lib/hybag/ingester.rb in hybag-0.1.1 vs lib/hybag/ingester.rb in hybag-0.2.0
- old
+ new
@@ -1,10 +1,10 @@
require 'rdf/rdfxml'
module Hybag
class Ingester
- attr_accessor :bag, :model_name
+ attr_accessor :bag, :model_name, :old_subject
def initialize(bag)
@bag = bag
end
def ingest
@@ -61,21 +61,20 @@
# TODO: Deal with what happens when there's no defined datastream.
def replace_subject(content, ds)
ds.content = content
if ds.respond_to?(:rdf_subject)
# Assume the first subject in the metadata is about this object.
- # TODO: Move this to configuration?
- first_subject = ds.graph.first_subject
+ old_subject = self.old_subject || ds.graph.first_subject
new_repository = RDF::Repository.new
ds.graph.each_statement do |statement|
- subject = statement.subject
- subject = ds.rdf_subject if subject == first_subject
- new_repository << [subject, statement.predicate, statement.object]
+ if statement.subject == old_subject
+ ds.graph.delete statement
+ ds.graph << RDF::Statement.new(ds.rdf_subject, statement.predicate, statement.object)
+ end
end
- ds.instance_variable_set(:@graph,new_repository)
end
- return ds
+ ds
end
def set_file_streams(object)
bag.bag_files.each do |bag_file|
add_bag_file_to_object(object, bag_file)
@@ -101,6 +100,6 @@
def fedora_rels
File.join(bag.bag_dir,"fedora","RELS-EXT.rdf")
end
end
-end
\ No newline at end of file
+end