Class: Hybag::BagWriter
- Inherits:
-
Object
- Object
- Hybag::BagWriter
- Defined in:
- lib/hybag/bag_writer.rb
Instance Attribute Summary collapse
-
#bag ⇒ Object
readonly
Returns the value of attribute bag.
-
#object ⇒ Object
readonly
Returns the value of attribute object.
Instance Method Summary collapse
-
#initialize(object) ⇒ BagWriter
constructor
A new instance of BagWriter.
- #write! ⇒ Object
Constructor Details
#initialize(object) ⇒ BagWriter
Returns a new instance of BagWriter.
5 6 7 8 |
# File 'lib/hybag/bag_writer.rb', line 5 def initialize(object) @object = object @bag = object.bag end |
Instance Attribute Details
#bag ⇒ Object (readonly)
Returns the value of attribute bag.
3 4 5 |
# File 'lib/hybag/bag_writer.rb', line 3 def bag @bag end |
#object ⇒ Object (readonly)
Returns the value of attribute object.
4 5 6 |
# File 'lib/hybag/bag_writer.rb', line 4 def object @object end |
Instance Method Details
#write! ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/hybag/bag_writer.rb', line 9 def write! # add the datastreams to the bag, then manifest @object.datastreams.each do |label, ds| unless ds.content.nil? label = label + mime_extension(ds) if .include? ds bag.add_tag_file(label) { |f| f.puts ds.content } elsif .values.include? ds bag.add_tag_file('fedora/' + label) { |f| f.puts ds.content } else bag.add_file(label) { |f| content = ds.content content = ds.content.read if ds.content.respond_to?(:read) f.puts content.force_encoding('UTF-8') } end end end bag.tagmanifest! bag.manifest! return bag end |