Class: WordTree::Librarian
- Inherits:
-
Object
- Object
- WordTree::Librarian
- Defined in:
- lib/wordtree/librarian.rb
Instance Attribute Summary collapse
-
#library ⇒ Object
readonly
Returns the value of attribute library.
Instance Method Summary collapse
-
#archive_org_get(conditions, &block) ⇒ Object
Downloads a set of books to the on-disk library and returns a list of book_ids.
- #archive_org_get_book(book_id, &block) ⇒ Object
- #archive_org_get_range_of_years(start_year, end_year, &block) ⇒ Object
- #find(book_id) ⇒ Object
-
#initialize(library) ⇒ Librarian
constructor
A new instance of Librarian.
- #save(book) ⇒ Object
Constructor Details
#initialize(library) ⇒ Librarian
Returns a new instance of Librarian.
10 11 12 |
# File 'lib/wordtree/librarian.rb', line 10 def initialize(library) @library = library end |
Instance Attribute Details
#library ⇒ Object (readonly)
Returns the value of attribute library.
8 9 10 |
# File 'lib/wordtree/librarian.rb', line 8 def library @library end |
Instance Method Details
#archive_org_get(conditions, &block) ⇒ Object
Downloads a set of books to the on-disk library and returns a list of book_ids
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/wordtree/librarian.rb', line 39 def archive_org_get(conditions, &block) archdown = Archdown.new [].tap do |archive_org_ids| archdown.download_all(conditions) do |, content, failure| if failure #TODO: logging $stderr.puts "Unable to download from archive.org: #{failure}" else book = Book.create(["archive_org_id"], , content) save(book) yield book, self if block_given? archive_org_ids << book.id end end end end |
#archive_org_get_book(book_id, &block) ⇒ Object
24 25 26 27 28 |
# File 'lib/wordtree/librarian.rb', line 24 def archive_org_get_book(book_id, &block) archive_org_get({ :filters => ["identifier:#{book_id}"] }, &block) end |
#archive_org_get_range_of_years(start_year, end_year, &block) ⇒ Object
30 31 32 33 34 35 |
# File 'lib/wordtree/librarian.rb', line 30 def archive_org_get_range_of_years(start_year, end_year, &block) archive_org_get({ :start_year => start_year, :end_year => end_year }, &block) end |
#find(book_id) ⇒ Object
14 15 16 17 |
# File 'lib/wordtree/librarian.rb', line 14 def find(book_id) retrieved = Preamble.load(library.path_to(book_id)) Book.create(book_id, retrieved., retrieved.content) end |
#save(book) ⇒ Object
19 20 21 22 |
# File 'lib/wordtree/librarian.rb', line 19 def save(book) library.mkdir(book.id) Preamble.new(book., book.content).save(library.path_to(book.id)) end |