Class: Kindai::BookDownloader
- Inherits:
-
Object
- Object
- Kindai::BookDownloader
- Defined in:
- lib/kindai/book_downloader.rb
Instance Attribute Summary collapse
-
#base_path ⇒ Object
Returns the value of attribute base_path.
-
#book ⇒ Object
Returns the value of attribute book.
-
#retry_count ⇒ Object
Returns the value of attribute retry_count.
Class Method Summary collapse
Instance Method Summary collapse
- #book_path ⇒ Object
- #create_directory ⇒ Object
- #delete ⇒ Object
- #download ⇒ Object
- #has_file? ⇒ Boolean
- #metadata_path ⇒ Object
- #safe_filename(filename) ⇒ Object
- #write_metadata ⇒ Object
Instance Attribute Details
#base_path ⇒ Object
Returns the value of attribute base_path.
6 7 8 |
# File 'lib/kindai/book_downloader.rb', line 6 def base_path @base_path end |
#book ⇒ Object
Returns the value of attribute book.
4 5 6 |
# File 'lib/kindai/book_downloader.rb', line 4 def book @book end |
#retry_count ⇒ Object
Returns the value of attribute retry_count.
5 6 7 |
# File 'lib/kindai/book_downloader.rb', line 5 def retry_count @retry_count end |
Class Method Details
Instance Method Details
#book_path ⇒ Object
29 30 31 32 |
# File 'lib/kindai/book_downloader.rb', line 29 def book_path path = File.join(self.base_path, safe_filename([@book., @book.title].compact.join(' - '))) File. path end |
#create_directory ⇒ Object
34 35 36 |
# File 'lib/kindai/book_downloader.rb', line 34 def create_directory Dir.mkdir(book_path) unless File.directory?(book_path) end |
#delete ⇒ Object
38 39 40 41 42 |
# File 'lib/kindai/book_downloader.rb', line 38 def delete success = true FileUtils.rm_r(self.book_path) rescue success = false return success end |
#download ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/kindai/book_downloader.rb', line 17 def download create_directory return false if self.has_file? download_spreads return true end |
#has_file? ⇒ Boolean
54 55 56 |
# File 'lib/kindai/book_downloader.rb', line 54 def has_file? File.directory?(self.book_path) && self.spread_downloaders.all?(&:has_file?) end |
#metadata_path ⇒ Object
50 51 52 |
# File 'lib/kindai/book_downloader.rb', line 50 def File.join(book_path, 'metadata') end |
#safe_filename(filename) ⇒ Object
25 26 27 |
# File 'lib/kindai/book_downloader.rb', line 25 def safe_filename filename filename.gsub(File::SEPARATOR, '_') end |
#write_metadata ⇒ Object
44 45 46 47 48 |
# File 'lib/kindai/book_downloader.rb', line 44 def open(, 'w') {|f| f.puts book.permalink_uri } unless File.exists?() end |