Class: Kindai::SpreadDownloader
- Inherits:
-
Object
- Object
- Kindai::SpreadDownloader
- Defined in:
- lib/kindai/spread_downloader.rb
Instance Attribute Summary collapse
-
#book_path ⇒ Object
Returns the value of attribute book_path.
-
#retry_count ⇒ Object
Returns the value of attribute retry_count.
-
#spread ⇒ Object
Returns the value of attribute spread.
Class Method Summary collapse
Instance Method Summary collapse
- #create_directory ⇒ Object
- #delete ⇒ Object
- #download ⇒ Object
- #has_file? ⇒ Boolean
- #spread_path ⇒ Object
Instance Attribute Details
#book_path ⇒ Object
Returns the value of attribute book_path.
6 7 8 |
# File 'lib/kindai/spread_downloader.rb', line 6 def book_path @book_path end |
#retry_count ⇒ Object
Returns the value of attribute retry_count.
5 6 7 |
# File 'lib/kindai/spread_downloader.rb', line 5 def retry_count @retry_count end |
#spread ⇒ Object
Returns the value of attribute spread.
4 5 6 |
# File 'lib/kindai/spread_downloader.rb', line 4 def spread @spread end |
Class Method Details
.new_from_spread(spread) ⇒ Object
8 9 10 11 12 13 14 15 |
# File 'lib/kindai/spread_downloader.rb', line 8 def self.new_from_spread(spread) raise TypeError, "#{spread} is not Kindai::Spread" unless spread.is_a? Kindai::Spread me = self.new me.spread = spread me.retry_count = 30 me.book_path = Pathname.new(ENV["HOME"]).to_s me end |
Instance Method Details
#create_directory ⇒ Object
24 25 26 27 |
# File 'lib/kindai/spread_downloader.rb', line 24 def create_directory path = File.join self.book_path, "original" Dir.mkdir(path) unless File.directory?(path) end |
#delete ⇒ Object
34 35 36 |
# File 'lib/kindai/spread_downloader.rb', line 34 def delete return File.delete(self.spread_path) && true rescue false end |
#download ⇒ Object
17 18 19 20 21 22 |
# File 'lib/kindai/spread_downloader.rb', line 17 def download return false if self.has_file? self.create_directory self.download_spread return true end |
#has_file? ⇒ Boolean
38 39 40 |
# File 'lib/kindai/spread_downloader.rb', line 38 def has_file? File.size? self.spread_path end |
#spread_path ⇒ Object
29 30 31 32 |
# File 'lib/kindai/spread_downloader.rb', line 29 def spread_path path = File.join self.book_path, "original", "%03d.jpg" % self.spread.spread_number File. path end |