Module: Feedzirra::FeedUtilities

Included in:
Parser::Atom, Parser::AtomFeedBurner, Parser::ITunesRSS, Parser::ITunesRSSOwner, Parser::RSS
Defined in:
lib/feedzirra/feed_utilities.rb

Constant Summary collapse

UPDATABLE_ATTRIBUTES =
%w(title feed_url url last_modified etag)

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#etagObject

Returns the value of attribute etag.



6
7
8
# File 'lib/feedzirra/feed_utilities.rb', line 6

def etag
  @etag
end

#last_modifiedObject



8
9
10
11
12
13
# File 'lib/feedzirra/feed_utilities.rb', line 8

def last_modified
  @last_modified ||= begin
    entry = entries.reject {|e| e.published.nil? }.sort_by { |entry| entry.published if entry.published }.last
    entry ? entry.published : nil
  end
end

#new_entriesObject



19
20
21
# File 'lib/feedzirra/feed_utilities.rb', line 19

def new_entries
  @new_entries ||= []
end

#updated=(value) ⇒ Object (writeonly)

Sets the attribute updated

Parameters:

  • value

    the value to set the attribute updated to.



5
6
7
# File 'lib/feedzirra/feed_utilities.rb', line 5

def updated=(value)
  @updated = value
end

Instance Method Details

#has_new_entries?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/feedzirra/feed_utilities.rb', line 23

def has_new_entries?
  new_entries.size > 0
end

#sanitize_entries!Object



46
47
48
# File 'lib/feedzirra/feed_utilities.rb', line 46

def sanitize_entries!
  entries.each {|entry| entry.sanitize!}
end

#update_attribute(feed, name) ⇒ Object



38
39
40
41
42
43
44
# File 'lib/feedzirra/feed_utilities.rb', line 38

def update_attribute(feed, name)
  old_value, new_value = send(name), feed.send(name)

  if old_value != new_value
    send("#{name}=", new_value)
  end
end

#update_from_feed(feed) ⇒ Object



27
28
29
30
31
32
33
34
35
36
# File 'lib/feedzirra/feed_utilities.rb', line 27

def update_from_feed(feed)
  self.new_entries += find_new_entries_for(feed)
  self.entries.unshift(*self.new_entries)

  @updated = false
  UPDATABLE_ATTRIBUTES.each do |name|
    updated = update_attribute(feed, name)
    @updated ||= updated
  end
end

#updated?Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/feedzirra/feed_utilities.rb', line 15

def updated?
  @updated
end