lib/hybag/ingester.rb in hybag-0.0.11 vs lib/hybag/ingester.rb in hybag-0.1.0
- old
+ new
@@ -1,10 +1,10 @@
require 'rdf/rdfxml'
module Hybag
class Ingester
- attr_accessor :bag
+ attr_accessor :bag, :model_name
def initialize(bag)
@bag = bag
end
def ingest
@@ -15,10 +15,16 @@
set_metadata_streams(new_object)
set_file_streams(new_object)
return new_object
end
+ def model_name
+ # TODO: Add a default model_name configuration option?
+ @model_name ||= extract_model_from_rels
+
+ end
+
private
# TODO: Add some sort of configuration to map bag filenames -> dsids.
def set_metadata_streams(object)
bag_tag_files.each do |tag_file|
@@ -79,38 +85,19 @@
# TODO: Might consider decoration at some point.
def bag_filename_to_label(bag_filename)
Pathname.new(bag_filename).basename.sub_ext('').to_s
end
- def model_name
- # TODO: Add a default model_name configuration option?
- @model_name ||= extract_model_from_rels || extract_model_from_yaml
-
- end
-
def extract_model_from_rels
if File.exist?(fedora_rels)
filler_object = ActiveFedora::Base.new
rels_datastream = ActiveFedora::RelsExtDatastream.new
rels_datastream.model = filler_object
ActiveFedora::RelsExtDatastream.from_xml(File.read(fedora_rels).strip,rels_datastream)
model_name = ActiveFedora::ContentModel.known_models_for(filler_object).first
return model_name.to_s
end
return model_name
- end
-
- def extract_model_from_yaml
- model_name = nil
- if(File.exist?(yaml_config))
- conf = YAML.load(File.read(yaml_config))
- model_name = conf['model']
- end
- return model_name
- end
-
- def yaml_config
- File.join(bag.bag_dir,"hybag.yml")
end
def fedora_rels
File.join(bag.bag_dir,"fedora","RELS-EXT.rdf")
end
\ No newline at end of file