Class: Alexandria::LibraryCollection

Inherits:
Object
  • Object
show all
Includes:
Observable, Singleton
Defined in:
lib/alexandria/library_collection.rb

Constant Summary collapse

LIBRARY_ADDED =
1
LIBRARY_REMOVED =
2

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#all_librariesObject (readonly)

Returns the value of attribute all_libraries.



12
13
14
# File 'lib/alexandria/library_collection.rb', line 12

def all_libraries
  @all_libraries
end

#deleted_booksObject (readonly)

Returns the value of attribute deleted_books.



12
13
14
# File 'lib/alexandria/library_collection.rb', line 12

def deleted_books
  @deleted_books
end

#library_storeObject

Returns the value of attribute library_store.



13
14
15
# File 'lib/alexandria/library_collection.rb', line 13

def library_store
  @library_store
end

#ruined_booksObject (readonly)

Returns the value of attribute ruined_books.



12
13
14
# File 'lib/alexandria/library_collection.rb', line 12

def ruined_books
  @ruined_books
end

Instance Method Details

#add_library(library) ⇒ Object



46
47
48
49
# File 'lib/alexandria/library_collection.rb', line 46

def add_library(library)
  @all_libraries << library
  notify(LIBRARY_ADDED, library)
end

#all_regular_librariesObject



35
36
37
# File 'lib/alexandria/library_collection.rb', line 35

def all_regular_libraries
  @all_libraries.select { |x| x.is_a?(Library) }
end

#all_smart_librariesObject



39
40
41
# File 'lib/alexandria/library_collection.rb', line 39

def all_smart_libraries
  @all_libraries.select { |x| x.is_a?(SmartLibrary) }
end

#really_delete_deleted_librariesObject



56
57
58
59
# 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_booksObject



61
62
63
64
65
# 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

#reloadObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# 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) ⇒ Object



51
52
53
54
# File 'lib/alexandria/library_collection.rb', line 51

def remove_library(library)
  @all_libraries.delete(library)
  notify(LIBRARY_REMOVED, library)
end