Module: Hybag

Defined in:
lib/hybag.rb,
lib/hybag/version.rb,
lib/hybag/baggable.rb,
lib/hybag/ingester.rb,
lib/hybag/validator.rb,
lib/hybag/bag_writer.rb

Defined Under Namespace

Modules: Baggable Classes: BagWriter, BulkIngester, Ingester, InvalidBaggable, UndiscoverableModelName, Validator

Constant Summary collapse

VERSION =
"0.2.0"

Class Method Summary collapse

Class Method Details

.bulk_directory?(directory) ⇒ Boolean

Returns:

  • (Boolean)

30
31
32
# File 'lib/hybag.rb', line 30

def self.bulk_directory?(directory)
  Dir.glob(File.join(directory,"*")).select{|x| File.directory?(x) && File.exist?(File.join(x, "bagit.txt"))}.length > 0
end

.bulk_ingest(directory) ⇒ Object


21
22
23
24
25
26
27
28
# File 'lib/hybag.rb', line 21

def self.bulk_ingest(directory)
  objects = []
  Hybag::BulkIngester.new(directory).each do |ingester|
    yield(ingester) if block_given?
    objects << ingester.ingest
  end
  return objects
end

.ingest(bag) {|ingester| ... } ⇒ Object

Yields:

  • (ingester)

13
14
15
16
17
18
19
# File 'lib/hybag.rb', line 13

def self.ingest(bag)
  return self.bulk_ingest(bag) if self.bulk_directory?(bag)
  bag = BagIt::Bag.new(bag.to_s) unless bag.kind_of?(BagIt::Bag)
  ingester = Hybag::Ingester.new(bag)
  yield(ingester) if block_given?
  ingester.ingest
end