class Alexandria::LibraryCollection

Constants

LIBRARY_ADDED
LIBRARY_REMOVED

Attributes

all_libraries[R]
deleted_books[R]
library_store[RW]
ruined_books[R]

Public Class Methods

new() click to toggle source
# File lib/alexandria/library_collection.rb, line 69
def initialize
  @all_libraries = []
  @deleted_books = []
end

Public Instance Methods

add_library(library) click to toggle source
# File lib/alexandria/library_collection.rb, line 46
def add_library(library)
  @all_libraries << library
  notify(LIBRARY_ADDED, library)
end
all_regular_libraries() click to toggle source
# File lib/alexandria/library_collection.rb, line 35
def all_regular_libraries
  @all_libraries.select { |x| x.is_a?(Library) }
end
all_smart_libraries() click to toggle source
# File lib/alexandria/library_collection.rb, line 39
def all_smart_libraries
  @all_libraries.select { |x| x.is_a?(SmartLibrary) }
end
really_delete_deleted_libraries() click to toggle source
# File lib/alexandria/library_collection.rb, line 56
def really_delete_deleted_libraries
  Library.really_delete_deleted_libraries
  SmartLibrary.really_delete_deleted_libraries
end
really_save_all_books() click to toggle source
# File lib/alexandria/library_collection.rb, line 61
def really_save_all_books
  all_regular_libraries.each do |library|
    library.each { |book| library.save(book, true) }
  end
end
reload() click to toggle source
# File lib/alexandria/library_collection.rb, line 18
def reload
  @all_libraries.clear
  @all_libraries.concat(library_store.load_all_libraries)
  @all_libraries.concat(library_store.load_all_smart_libraries)

  ruined = []
  deleted = []
  all_regular_libraries.each do |library|
    ruined += library.ruined_books
    # make deleted books from each library accessible so we don't crash on
    # smart libraries
    deleted += library.deleted_books
  end
  @ruined_books = ruined
  @deleted_books = deleted
end
remove_library(library) click to toggle source
# File lib/alexandria/library_collection.rb, line 51
def remove_library(library)
  @all_libraries.delete(library)
  notify(LIBRARY_REMOVED, library)
end

Private Instance Methods

notify(action, library) click to toggle source
# File lib/alexandria/library_collection.rb, line 74
def notify(action, library)
  changed
  notify_observers(self, action, library)
end