Class: Pic2ch::Downloaders::Thread
- Inherits:
-
Object
- Object
- Pic2ch::Downloaders::Thread
- Defined in:
- lib/pic2ch/downloaders/thread.rb
Instance Method Summary collapse
- #base_path ⇒ Object
- #command(type = :images) ⇒ Object
- #done?(type = :images) ⇒ Boolean
- #done_flag_for(type = :images) ⇒ Object
- #execute(type = :images) ⇒ Object
- #images_path_for(type = :images) ⇒ Object
-
#initialize(thread) ⇒ Thread
constructor
A new instance of Thread.
- #request(type = nil) ⇒ Object
- #requested?(type = :images) ⇒ Boolean
Constructor Details
#initialize(thread) ⇒ Thread
Returns a new instance of Thread.
6 7 8 |
# File 'lib/pic2ch/downloaders/thread.rb', line 6 def initialize(thread) @thread = thread end |
Instance Method Details
#base_path ⇒ Object
10 11 12 13 14 15 16 |
# File 'lib/pic2ch/downloaders/thread.rb', line 10 def base_path @base_path ||= ( path = Pic2ch.root + Pic2ch::Thread.image_url.host + "urls" + time.to_s path.mkpath path ) end |
#command(type = :images) ⇒ Object
44 45 46 |
# File 'lib/pic2ch/downloaders/thread.rb', line 44 def command(type = :images) "wget -x -i %s > %s 2>&1" % [images_path_for(type), done_flag_for(type)] end |
#done?(type = :images) ⇒ Boolean
40 41 42 |
# File 'lib/pic2ch/downloaders/thread.rb', line 40 def done?(type = :images) done_flag_for(type).exist? end |
#done_flag_for(type = :images) ⇒ Object
36 37 38 |
# File 'lib/pic2ch/downloaders/thread.rb', line 36 def done_flag_for(type = :images) base_path + "#{type}.log" end |
#execute(type = :images) ⇒ Object
48 49 50 51 |
# File 'lib/pic2ch/downloaders/thread.rb', line 48 def execute(type = :images) request(type) system(command(type)) end |
#images_path_for(type = :images) ⇒ Object
18 19 20 |
# File 'lib/pic2ch/downloaders/thread.rb', line 18 def images_path_for(type = :images) base_path + "#{type}.txt" end |
#request(type = nil) ⇒ Object
22 23 24 25 26 27 28 29 30 |
# File 'lib/pic2ch/downloaders/thread.rb', line 22 def request(type = nil) if type requested?(type) or images_path_for(type).open("w+"){|f| f.puts @thread.send(type)} else request(:thumbs) request(:images) end end |
#requested?(type = :images) ⇒ Boolean
32 33 34 |
# File 'lib/pic2ch/downloaders/thread.rb', line 32 def requested?(type = :images) images_path_for(type).exist? end |