class Repository

Attributes

collections[R]
size[RW]

Public Class Methods

new(aliases) click to toggle source
# File lib/hunting/repository.rb, line 10
def initialize(aliases)
  @progressbar = Hunting.progressbar('repository', Hunting.config[:cdm]['name'])
  @size = 0
  @not_found = []
  @collections = scout(aliases)
  @progressbar.finish
  if @not_found.size > 0
    print 'Scout failed for: '
    @not_found.each {|collection| print "#{collection} "}
    print "\n"
  end
end
scout(aliases = 'all') click to toggle source
# File lib/hunting/repository.rb, line 6
def self.scout(aliases = 'all')
  Repository.new(aliases)
end

Public Instance Methods

scout(aliases) click to toggle source
# File lib/hunting/repository.rb, line 23
def scout(aliases)
  collections = {}
  collection_info = {}

  if Hunting.config[:dmwebservices] == nil
    @progressbar.finish
    abort("\nPlease configure Hunting for your CONTENTdm server:
           \nHunting.configure(config_hash)\nOR\nHunting.configure_with(\"/path/to/config.yml\")\n")
  else
    cdm_collection_data = JSON.parse(open(Hunting.config[:dmwebservices] + "dmGetCollectionList/json").read)
  end

  cdm_collection_data.each do |collection|
    collection_info.store(collection['secondary_alias'], {:alias => collection['secondary_alias'], :name => collection['name']})
  end

  if aliases == 'all'
    collection_info.each do |collection_alias, info|
      collections.store(collection_alias, Collection.new({:alias => collection_alias, :name => info[:name]}))
    end
  else
    aliases.each do |c_alias|
      if collection_info[c_alias] == nil
        @not_found.push(c_alias)
      else
        collections.store(c_alias, Collection.new({:alias => c_alias, :name => collection_info[c_alias][:name]}))
      end
    end
  end
  collections.each {|c_alias, collection| @size += collection.size}
  collections
end