Module: Feedzirra::FeedUtilities

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

Constant Summary collapse

UPDATABLE_ATTRIBUTES =
%w(title feed_url url last_modified)

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#entries=(value) ⇒ Object (writeonly)

Sets the attribute entries

Parameters:

  • value

    the value to set the attribute entries to.



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

def entries=(value)
  @entries = value
end

#etagObject

Returns the value of attribute etag.



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

def etag
  @etag
end

#last_modifiedObject



13
14
15
16
17
18
# File 'lib/feedzirra/parser/feed_utilities.rb', line 13

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

#updated=(value) ⇒ Object (writeonly)

Sets the attribute updated

Parameters:

  • value

    the value to set the attribute updated to.



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

def updated=(value)
  @updated = value
end

Instance Method Details

#has_new_entries?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/feedzirra/parser/feed_utilities.rb', line 34

def has_new_entries?
  new_entries.size > 0
end

#initializeObject



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

def initialize
  @entries = []
  super
end

#new_entriesObject



30
31
32
# File 'lib/feedzirra/parser/feed_utilities.rb', line 30

def new_entries
  @entries.select{ |e| e.new_entry? }
end

#sanitize_entries!Object



58
59
60
# File 'lib/feedzirra/parser/feed_utilities.rb', line 58

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

#update_attribute(feed, name) ⇒ Object



50
51
52
53
54
55
56
# File 'lib/feedzirra/parser/feed_utilities.rb', line 50

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



38
39
40
41
42
43
44
45
46
47
48
# File 'lib/feedzirra/parser/feed_utilities.rb', line 38

def update_from_feed(feed)
  # Mark all existing entries as old, then add new entries, which are
  # marked as new by default.
  self.entries.each{|e| e.mark_old! }

  find_new_entries_for(feed).each do |e|
    self.entries << e
  end
  
  updated! if UPDATABLE_ATTRIBUTES.any? { |name| update_attribute(feed, name) }
end

#updated?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/feedzirra/parser/feed_utilities.rb', line 26

def updated?
  @updated
end