Module: Feedjira::FeedUtilities
- Included in:
- Parser::Atom, Parser::AtomFeedBurner, Parser::AtomGoogleAlerts, Parser::AtomYoutube, Parser::GoogleDocsAtom, Parser::ITunesRSS, Parser::ITunesRSSOwner, Parser::JSONFeed, 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].freeze
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
- #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.
8 9 10 |
# File 'lib/feedjira/feed_utilities.rb', line 8 def etag @etag end |
#last_modified ⇒ Object
43 44 45 |
# File 'lib/feedjira/feed_utilities.rb', line 43 def last_modified @last_modified ||= entries.reject { |e| e.published.nil? }.max_by(&:published)&.published end |
#new_entries ⇒ Object
51 52 53 |
# File 'lib/feedjira/feed_utilities.rb', line 51 def new_entries @new_entries ||= [] end |
#updated=(value) ⇒ Object (writeonly)
Sets the attribute updated
7 8 9 |
# File 'lib/feedjira/feed_utilities.rb', line 7 def updated=(value) @updated = value end |
Class Method Details
.included(base) ⇒ Object
10 11 12 |
# File 'lib/feedjira/feed_utilities.rb', line 10 def self.included(base) base.extend ClassMethods end |
Instance Method Details
#new_entries? ⇒ Boolean
55 56 57 |
# File 'lib/feedjira/feed_utilities.rb', line 55 def new_entries? !new_entries.empty? end |
#sanitize_entries! ⇒ Object
82 83 84 |
# File 'lib/feedjira/feed_utilities.rb', line 82 def sanitize_entries! entries.each(&:sanitize!) end |
#update_attribute(feed, name) ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/feedjira/feed_utilities.rb', line 70 def update_attribute(feed, name) old_value = send(name) new_value = feed.send(name) if old_value == new_value false else send(:"#{name}=", new_value) true end end |
#update_from_feed(feed) ⇒ Object
59 60 61 62 63 64 65 66 67 68 |
# File 'lib/feedjira/feed_utilities.rb', line 59 def update_from_feed(feed) self.new_entries += find_new_entries_for(feed) entries.unshift(*self.new_entries) @updated = false UPDATABLE_ATTRIBUTES.each do |name| @updated ||= update_attribute(feed, name) end end |
#updated? ⇒ Boolean
47 48 49 |
# File 'lib/feedjira/feed_utilities.rb', line 47 def updated? @updated || false end |