Class: ChanCrawlerGem::DownloadManager
- Inherits:
-
Object
- Object
- ChanCrawlerGem::DownloadManager
- Defined in:
- lib/chanCrawlerGem.rb
Instance Attribute Summary collapse
-
#download_dest ⇒ Object
readonly
Returns the value of attribute download_dest.
Instance Method Summary collapse
- #already_present?(item_name) ⇒ Boolean
- #download(resource_url) ⇒ Object
- #download_thread_contents(urls) ⇒ Object
- #get_thread_contents(thread) ⇒ Object
-
#initialize(download_destination) ⇒ DownloadManager
constructor
A new instance of DownloadManager.
Constructor Details
#initialize(download_destination) ⇒ DownloadManager
Returns a new instance of DownloadManager.
74 75 76 |
# File 'lib/chanCrawlerGem.rb', line 74 def initialize(download_destination) @download_dest = download_destination end |
Instance Attribute Details
#download_dest ⇒ Object (readonly)
Returns the value of attribute download_dest.
72 73 74 |
# File 'lib/chanCrawlerGem.rb', line 72 def download_dest @download_dest end |
Instance Method Details
#already_present?(item_name) ⇒ Boolean
99 100 101 102 |
# File 'lib/chanCrawlerGem.rb', line 99 def already_present?(item_name) name = item_name.slice(15, item_name.length) false unless File.file?("#{download_dest}/#{name}") end |
#download(resource_url) ⇒ Object
91 92 93 94 95 96 97 |
# File 'lib/chanCrawlerGem.rb', line 91 def download(resource_url) puts "Downloading #{resource_url}" tmpfile = Down.download("http:#{resource_url}") FileUtils.mv(tmpfile.path, "#{download_dest}#{tmpfile .original_filename}") puts 'Downloaded successfully' end |
#download_thread_contents(urls) ⇒ Object
85 86 87 88 89 |
# File 'lib/chanCrawlerGem.rb', line 85 def download_thread_contents(urls) urls.each do |url| download(url) if already_present?(url) == false end end |
#get_thread_contents(thread) ⇒ Object
78 79 80 81 82 83 |
# File 'lib/chanCrawlerGem.rb', line 78 def get_thread_contents(thread) # puts "Parsing #{thread} for content" document = Nokogiri::HTML(URI.open(thread)) results = document.css('.board .fileThumb') result_links = results.map { |t| t[:href] } end |