Module: SK::Downloads
Instance Method Summary collapse
- #count ⇒ Object
- #delete_all ⇒ Object
- #delete_any(name) ⇒ Object
- #determine_mac_path ⇒ Object
- #downloaded? ⇒ Boolean
- #downloading? ⇒ Boolean
- #files ⇒ Object
- #include?(filename) ⇒ Boolean
- #last ⇒ Object
- #last_name ⇒ Object
- #names ⇒ Object
- #path ⇒ Object
- #path=(p) ⇒ Object
-
#wait_for_download ⇒ Object
def first_content wait_for_download File.read(first) end.
Instance Method Details
#count ⇒ Object
45 46 47 |
# File 'lib/downloads.rb', line 45 def count files.length end |
#delete_all ⇒ Object
77 78 79 |
# File 'lib/downloads.rb', line 77 def delete_all FileUtils.rm_f(files) end |
#delete_any(name) ⇒ Object
72 73 74 75 |
# File 'lib/downloads.rb', line 72 def delete_any(name) list = files.select { |f| File.basename(f).include?(name) } FileUtils.rm_f(list) end |
#determine_mac_path ⇒ Object
15 16 17 18 19 |
# File 'lib/downloads.rb', line 15 def determine_mac_path parts = File.dirname(__FILE__).split("/") # will work for AR and PC on a Mac (for now) "/#{parts[1]}/#{parts[2]}/downloads" end |
#downloaded? ⇒ Boolean
64 65 66 |
# File 'lib/downloads.rb', line 64 def downloaded? !downloading? && files.any? end |
#downloading? ⇒ Boolean
68 69 70 |
# File 'lib/downloads.rb', line 68 def downloading? files.grep(/\.part$/).any? end |
#files ⇒ Object
21 22 23 24 25 26 |
# File 'lib/downloads.rb', line 21 def files # NOTE: every time this is called it goes out to the OS for # a fresh list of the files... we may want to change to a # "refresh" or "readfiles" model for performance Dir["#{self.path}/*"] end |
#include?(filename) ⇒ Boolean
32 33 34 35 |
# File 'lib/downloads.rb', line 32 def include?(filename) filepath = "#{path}/#{filename}" files.include? filepath end |
#last ⇒ Object
37 38 39 |
# File 'lib/downloads.rb', line 37 def last files.max_by {|f| File.mtime(f)} end |
#last_name ⇒ Object
41 42 43 |
# File 'lib/downloads.rb', line 41 def last_name File.basename last # just the file name end |
#names ⇒ Object
28 29 30 |
# File 'lib/downloads.rb', line 28 def names files.collect {|f| File.basename(f) } end |
#path ⇒ Object
11 12 13 |
# File 'lib/downloads.rb', line 11 def path @path = @path || determine_mac_path end |
#path=(p) ⇒ Object
7 8 9 |
# File 'lib/downloads.rb', line 7 def path=(p) @path = p end |
#wait_for_download ⇒ Object
def first_content
wait_for_download
File.read(first)
end
58 59 60 61 62 |
# File 'lib/downloads.rb', line 58 def wait_for_download Timeout.timeout(1) do sleep 0.1 until downloaded? end end |