Class: FYT::Storage
Overview
Manages file downloads and storage
Instance Method Summary collapse
- #add(item) ⇒ Object
- #add_feed(name, feed) ⇒ Object
- #cleanup! ⇒ Object
-
#initialize(path, format_options, output_format, proxy = nil) ⇒ Storage
constructor
A new instance of Storage.
- #mtime(filename) ⇒ Object
- #size(filename) ⇒ Object
Methods inherited from Base
Constructor Details
#initialize(path, format_options, output_format, proxy = nil) ⇒ Storage
Returns a new instance of Storage.
5 6 7 8 9 10 11 |
# File 'lib/fyt/storage.rb', line 5 def initialize(path, , output_format, proxy = nil) @path = path || '' @format_options = @output_format = output_format @proxy = proxy @known_files = [] end |
Instance Method Details
#add(item) ⇒ Object
13 14 15 16 17 18 19 20 |
# File 'lib/fyt/storage.rb', line 13 def add(item) url = item.link.href path = path_for(item) download_file!(url, path) @known_files << File.basename(path) File.basename(path) end |
#add_feed(name, feed) ⇒ Object
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/fyt/storage.rb', line 22 def add_feed(name, feed) logger.debug feed.to_s logger.debug @known_files File.join(@path, "#{name}.feed.rss20.xml").tap do |path| File.write(path, feed) @known_files << File.basename(path) end end |
#cleanup! ⇒ Object
33 34 35 36 37 38 39 40 |
# File 'lib/fyt/storage.rb', line 33 def cleanup! logger.debug 'Files to delete:' logger.debug files_to_delete files_to_delete.each do |filename| delete_file! filename end end |
#mtime(filename) ⇒ Object
42 43 44 |
# File 'lib/fyt/storage.rb', line 42 def mtime(filename) File.mtime(File.join(@path, filename)) end |
#size(filename) ⇒ Object
46 47 48 |
# File 'lib/fyt/storage.rb', line 46 def size(filename) File.size(File.join(@path, filename)) end |