Module: Feedjira::FeedUtilities
- Included in:
- Parser::Atom, Parser::AtomFeedBurner, Parser::GoogleDocsAtom, Parser::ITunesRSS, Parser::ITunesRSSOwner, Parser::RSS, Parser::RSSFeedBurner
- Defined in:
- lib/feedjira/feed_utilities.rb
Defined Under Namespace
Modules: ClassMethods
Constant Summary collapse
- UPDATABLE_ATTRIBUTES =
%w(title feed_url url last_modified etag)
Instance Attribute Summary collapse
-
#etag ⇒ Object
Returns the value of attribute etag.
- #last_modified ⇒ Object
- #new_entries ⇒ Object
-
#updated ⇒ Object
writeonly
Sets the attribute updated.
Class Method Summary collapse
Instance Method Summary collapse
- #has_new_entries? ⇒ Boolean
- #sanitize_entries! ⇒ Object
- #update_attribute(feed, name) ⇒ Object
- #update_from_feed(feed) ⇒ Object
- #updated? ⇒ Boolean
Instance Attribute Details
#etag ⇒ Object
Returns the value of attribute etag.
6 7 8 |
# File 'lib/feedjira/feed_utilities.rb', line 6 def etag @etag end |
#last_modified ⇒ Object
33 34 35 36 37 38 |
# File 'lib/feedjira/feed_utilities.rb', line 33 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_entries ⇒ Object
44 45 46 |
# File 'lib/feedjira/feed_utilities.rb', line 44 def new_entries @new_entries ||= [] end |
#updated=(value) ⇒ Object (writeonly)
Sets the attribute updated
5 6 7 |
# File 'lib/feedjira/feed_utilities.rb', line 5 def updated=(value) @updated = value end |
Class Method Details
.included(base) ⇒ Object
8 9 10 |
# File 'lib/feedjira/feed_utilities.rb', line 8 def self.included(base) base.extend ClassMethods end |
Instance Method Details
#has_new_entries? ⇒ Boolean
48 49 50 |
# File 'lib/feedjira/feed_utilities.rb', line 48 def has_new_entries? new_entries.size > 0 end |
#sanitize_entries! ⇒ Object
74 75 76 |
# File 'lib/feedjira/feed_utilities.rb', line 74 def sanitize_entries! entries.each {|entry| entry.sanitize!} end |
#update_attribute(feed, name) ⇒ Object
63 64 65 66 67 68 69 70 71 72 |
# File 'lib/feedjira/feed_utilities.rb', line 63 def update_attribute(feed, name) old_value, new_value = send(name), feed.send(name) if old_value != new_value send("#{name}=", new_value) true else false end end |
#update_from_feed(feed) ⇒ Object
52 53 54 55 56 57 58 59 60 61 |
# File 'lib/feedjira/feed_utilities.rb', line 52 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) end end |
#updated? ⇒ Boolean
40 41 42 |
# File 'lib/feedjira/feed_utilities.rb', line 40 def updated? @updated || false end |