Module: BagIt::Info

Included in:
Bag
Defined in:
lib/bagit/info.rb

Constant Summary collapse

@@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'
}

Instance Method Summary collapse

Instance Method Details

#bag_infoObject



29
30
31
32
33
34
35
# File 'lib/bagit/info.rb', line 29

def bag_info
  begin
    read_info_file bag_info_txt_file
  rescue
    {}
  end
end

#bag_info_txt_fileObject



25
26
27
# File 'lib/bagit/info.rb', line 25

def bag_info_txt_file
  File.join bag_dir, 'bag-info.txt'
end

#bagitObject



49
50
51
# File 'lib/bagit/info.rb', line 49

def bagit
  read_info_file bagit_txt_file
end

#bagit_txt_fileObject



45
46
47
# File 'lib/bagit/info.rb', line 45

def bagit_txt_file
  File.join bag_dir, 'bagit.txt'
end

#update_bag_dateObject



57
58
59
60
# File 'lib/bagit/info.rb', line 57

def update_bag_date
  hash["Bagging-Date"] = Date.today.strftime('%Y-%m-%d')
  write_bag_info(hash)
end

#write_bag_info(hash = {}) ⇒ Object



37
38
39
40
41
42
43
# File 'lib/bagit/info.rb', line 37

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

#write_bagit(hash) ⇒ Object



53
54
55
# File 'lib/bagit/info.rb', line 53

def write_bagit(hash)
  write_info_file bagit_txt_file, hash
end