Class: TransmissionRSS::SeenFile

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/transmission-rss/seen_file.rb

Overview

Persist seen torrent URLs

Instance Method Summary collapse

Constructor Details

#initialize(path = nil) ⇒ SeenFile

Returns a new instance of SeenFile.



13
14
15
16
17
18
# File 'lib/transmission-rss/seen_file.rb', line 13

def initialize(path = nil)
  @path = path || default_path
  initialize_path!(@path)

  @seen = Set.new(file_to_array(@path))
end

Instance Method Details

#add(url) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/transmission-rss/seen_file.rb', line 20

def add(url)
  hash = digest(url)

  return if @seen.include?(hash)

  @seen << hash

  open(@path, 'a') do |f|
    f.write(hash + "\n")
  end
end

#clear!Object



32
33
34
35
# File 'lib/transmission-rss/seen_file.rb', line 32

def clear!
  @seen.clear
  open(@path, 'w') {}
end

#include?(url) ⇒ Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/transmission-rss/seen_file.rb', line 37

def include?(url)
  @seen.include?(digest(url))
end