Class: Archdown::Librarian
- Inherits:
-
Object
- Object
- Archdown::Librarian
- Defined in:
- lib/archdown/librarian.rb
Overview
The Librarian takes a book and puts it in the library
Instance Attribute Summary collapse
-
#book ⇒ Object
readonly
Returns the value of attribute book.
-
#library ⇒ Object
readonly
Returns the value of attribute library.
Instance Method Summary collapse
- #book_dir ⇒ Object
- #book_filepath ⇒ Object
-
#initialize(library, book) ⇒ Librarian
constructor
A new instance of Librarian.
- #make_book_dir ⇒ Object
- #metadata ⇒ Object
- #store_book {|metadata, _self| ... } ⇒ Object
Constructor Details
#initialize(library, book) ⇒ Librarian
Returns a new instance of Librarian.
11 12 13 14 15 |
# File 'lib/archdown/librarian.rb', line 11 def initialize(library, book) @library = library @book = book @failure = nil end |
Instance Attribute Details
#book ⇒ Object (readonly)
Returns the value of attribute book.
9 10 11 |
# File 'lib/archdown/librarian.rb', line 9 def book @book end |
#library ⇒ Object (readonly)
Returns the value of attribute library.
9 10 11 |
# File 'lib/archdown/librarian.rb', line 9 def library @library end |
Instance Method Details
#book_dir ⇒ Object
30 31 32 |
# File 'lib/archdown/librarian.rb', line 30 def book_dir @library.path_for_identifier(@book.identifier) end |
#book_filepath ⇒ Object
34 35 36 |
# File 'lib/archdown/librarian.rb', line 34 def book_filepath File.join(book_dir, @book.identifier + '.md') end |
#make_book_dir ⇒ Object
38 39 40 |
# File 'lib/archdown/librarian.rb', line 38 def make_book_dir FileUtils.mkdir_p(book_dir) end |
#metadata ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/archdown/librarian.rb', line 17 def { '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 || ['failure'] = @failure if @failure end end |
#store_book {|metadata, _self| ... } ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# 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 , self if block_given? content = .to_yaml content += "---\n" content += text if text File.open(book_filepath, "w") do |file| file.write content end end |