lib/bagit/info.rb in bagit-0.2.0 vs lib/bagit/info.rb in bagit-0.3.0.pre
- old
+ new
@@ -2,19 +2,45 @@
module BagIt
module Info
+ @@bag_info_headers = {
+ :agent => 'Bag-Software-Agent',
+ :org => 'Source-Organization',
+ :org_addr => 'Organization-Address',
+ :contact_name => 'Contact-Name',
+ :contact_phone => 'Contact-Phone',
+ :contact_email => 'Contact-Email',
+ :ext_desc => 'External-Description',
+ :ext_id => 'External-Identifier',
+ :size => 'Bag-Size',
+ :group_id => 'Bag-Group-Identifier',
+ :group_count => 'Bag-Count',
+ :sender_id => 'Internal-Sender-Identifier',
+ :int_desc => 'Internal-Sender-Description',
+ :date => 'Bagging-Date',
+ :oxum => 'Payload-Oxum'
+ }
+
def bag_info_txt_file
File.join bag_dir, 'bag-info.txt'
end
def bag_info
- read_info_file bag_info_txt_file
+ begin
+ read_info_file bag_info_txt_file
+ rescue
+ {}
+ end
end
- def write_bag_info(hash)
+ def write_bag_info(hash={})
+ hash = bag_info.merge(hash)
+ hash[@@bag_info_headers[:agent]] = "BagIt Ruby Gem (http://bagit.rubyforge.org)" if hash[@@bag_info_headers[:agent]].nil?
+ hash[@@bag_info_headers[:date]] = Date.today.strftime('%Y-%m-%d') if hash[@@bag_info_headers[:date]].nil?
+ hash[@@bag_info_headers[:oxum]] = payload_oxum
write_info_file bag_info_txt_file, hash
end
def bagit_txt_file
File.join bag_dir, 'bagit.txt'
@@ -24,9 +50,14 @@
read_info_file bagit_txt_file
end
def write_bagit(hash)
write_info_file bagit_txt_file, hash
+ end
+
+ def update_bag_date
+ hash["Bagging-Date"] = Date.today.strftime('%Y-%m-%d')
+ write_bag_info(hash)
end
protected
def read_info_file(file)