Class: Kindai::SpreadDownloader

Inherits:
Object
  • Object
show all
Defined in:
lib/kindai/spread_downloader.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#book_pathObject

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_countObject

Returns the value of attribute retry_count.



5
6
7
# File 'lib/kindai/spread_downloader.rb', line 5

def retry_count
  @retry_count
end

#spreadObject

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

Raises:

  • (TypeError)


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_directoryObject



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

#deleteObject



34
35
36
# File 'lib/kindai/spread_downloader.rb', line 34

def delete
  return File.delete(self.spread_path) && true rescue false
end

#downloadObject



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

Returns:

  • (Boolean)


38
39
40
# File 'lib/kindai/spread_downloader.rb', line 38

def has_file?
  File.size? self.spread_path
end

#spread_pathObject



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.expand_path path
end