Class: Feed2Email::Feed

Inherits:
Object
  • Object
show all
Includes:
Configurable, Loggable
Defined in:
lib/feed2email/feed.rb

Instance Method Summary collapse

Methods included from Loggable

#logger

Methods included from Configurable

#config

Instance Method Details

#old?Boolean

Returns:

  • (Boolean)


31
# File 'lib/feed2email/feed.rb', line 31

def old?; last_processed_at end

#processObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/feed2email/feed.rb', line 33

def process
  logger.info "Processing feed #{uri} ..."

  return false unless fetch_and_parse

  if processable?
    # Reset feed caching parameters unless all entries were processed. This
    # makes sure the feed will be fetched on next processing.
    unless process_entries
      self.last_modified = initial_value(:last_modified)
      self.etag = initial_value(:etag)
    end

    self.last_processed_at = Time.now

    save(changed: true)
  else
    logger.warn 'Feed does not have entries'
  end
end

#to_sObject



54
55
56
57
58
59
# File 'lib/feed2email/feed.rb', line 54

def to_s
  parts = [id.to_s.rjust(3)] # align right 1-999
  parts << "\e[31mDISABLED\e[0m" unless enabled
  parts << uri
  parts.join(' ')
end

#toggleObject



61
62
63
# File 'lib/feed2email/feed.rb', line 61

def toggle
  update(enabled: !enabled)
end

#uncacheObject



65
66
67
# File 'lib/feed2email/feed.rb', line 65

def uncache
  !cached? || update(last_modified: nil, etag: nil)
end