class Archdown::Librarian
The Librarian
takes a book and puts it in the library
Attributes
book[R]
library[R]
Public Class Methods
new(library, book)
click to toggle source
# File lib/archdown/librarian.rb, line 11 def initialize(library, book) @library = library @book = book @failure = nil end
Public Instance Methods
book_dir()
click to toggle source
# File lib/archdown/librarian.rb, line 30 def book_dir @library.path_for_identifier(@book.identifier) end
book_filepath()
click to toggle source
# File lib/archdown/librarian.rb, line 34 def book_filepath File.join(book_dir, @book.identifier + '.md') end
make_book_dir()
click to toggle source
# File lib/archdown/librarian.rb, line 38 def make_book_dir FileUtils.mkdir_p(book_dir) end
metadata()
click to toggle source
# File lib/archdown/librarian.rb, line 17 def metadata { 'title' => @book.title, 'author' => @book.creators ? @book.creators.join(';') : nil, 'year' => @book.date.year, 'source' => "http://archive.org/details/#{@book.identifier}", 'status' => "OCR ONLY", 'archive_org_id' => @book.identifier, }.tap do |meta| meta['failure'] = @failure if @failure end end
store_book() { |metadata, self| ... }
click to toggle source
# File lib/archdown/librarian.rb, line 42 def store_book(&block) make_book_dir begin text = @book.download rescue Archivist::Model::Document::UnsupportedFormat => e @failure = e.to_s rescue StandardError => e @failure = e.to_s end yield metadata, self if block_given? content = metadata.to_yaml content += "---\n" content += text if text File.open(book_filepath, "w") do |file| file.write content end end