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
-
#entries ⇒ Object
writeonly
Sets the attribute entries.
-
#etag ⇒ Object
Returns the value of attribute etag.
- #last_modified ⇒ Object
-
#updated ⇒ Object
writeonly
Sets the attribute updated.
Instance Method Summary collapse
- #has_new_entries? ⇒ Boolean
- #initialize ⇒ Object
- #new_entries ⇒ Object
- #sanitize_entries! ⇒ Object
- #update_attribute(feed, name) ⇒ Object
- #update_from_feed(feed) ⇒ Object
- #updated? ⇒ Boolean
Instance Attribute Details
#entries=(value) ⇒ Object (writeonly)
Sets the attribute entries
5 6 7 |
# File 'lib/feedzirra/parser/feed_utilities.rb', line 5 def entries=(value) @entries = value end |
#etag ⇒ Object
Returns the value of attribute etag.
6 7 8 |
# File 'lib/feedzirra/parser/feed_utilities.rb', line 6 def etag @etag end |
#last_modified ⇒ Object
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
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
34 35 36 |
# File 'lib/feedzirra/parser/feed_utilities.rb', line 34 def has_new_entries? new_entries.size > 0 end |
#initialize ⇒ Object
8 9 10 11 |
# File 'lib/feedzirra/parser/feed_utilities.rb', line 8 def initialize @entries = [] super end |
#new_entries ⇒ Object
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
26 27 28 |
# File 'lib/feedzirra/parser/feed_utilities.rb', line 26 def updated? @updated end |