Class: FYT::Storage

Inherits:
Base
  • Object
show all
Defined in:
lib/fyt/storage.rb

Overview

Manages file downloads and storage

Instance Method Summary collapse

Methods inherited from Base

#logger

Constructor Details

#initialize(path, format_options, output_format, proxy_manager) ⇒ Storage

Returns a new instance of Storage.



6
7
8
9
10
11
12
# File 'lib/fyt/storage.rb', line 6

def initialize(path, format_options, output_format, proxy_manager)
  @path = path || ''
  @format_options = format_options
  @output_format = output_format
  @proxy_manager = proxy_manager
  @known_files = []
end

Instance Method Details

#add(item) ⇒ Object



14
15
16
17
18
19
20
21
# File 'lib/fyt/storage.rb', line 14

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



23
24
25
26
27
28
29
30
31
32
# File 'lib/fyt/storage.rb', line 23

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



34
35
36
37
38
39
40
41
# File 'lib/fyt/storage.rb', line 34

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



43
44
45
# File 'lib/fyt/storage.rb', line 43

def mtime(filename)
  File.mtime(File.join(@path, filename))
end

#size(filename) ⇒ Object



47
48
49
# File 'lib/fyt/storage.rb', line 47

def size(filename)
  File.size(File.join(@path, filename))
end