Class: TorrentRSS::EntryLog

Inherits:
Object
  • Object
show all
Defined in:
lib/torrent_rss/entry_log.rb

Class Method Summary collapse

Class Method Details

.add(entry_id) ⇒ Object



26
27
28
29
# File 'lib/torrent_rss/entry_log.rb', line 26

def add entry_id
  entries << encode_entry(entry_id)
  save
end

.encode_entry(entry_id) ⇒ Object



22
23
24
# File 'lib/torrent_rss/entry_log.rb', line 22

def encode_entry entry_id
  Digest::MD5.hexdigest entry_id
end

.entriesObject



10
11
12
# File 'lib/torrent_rss/entry_log.rb', line 10

def entries
  @entries ||= read
end

.file_pathObject



35
36
37
# File 'lib/torrent_rss/entry_log.rb', line 35

def file_path
  File.expand_path("~/.torrent_rss_log")
end

.has?(entry_id) ⇒ Boolean

Returns:

  • (Boolean)


6
7
8
# File 'lib/torrent_rss/entry_log.rb', line 6

def has? entry_id
  entries.include? encode_entry(entry_id)
end

.readObject



14
15
16
17
18
19
20
# File 'lib/torrent_rss/entry_log.rb', line 14

def read
  if File.exists? file_path
    File.read(file_path).split("\n")
  else
    []
  end
end

.saveObject



31
32
33
# File 'lib/torrent_rss/entry_log.rb', line 31

def save
  File.write file_path, entries.join("\n")
end