Module: Feedjira::FeedUtilities

Defined Under Namespace

Modules: ClassMethods

Constant Summary

UPDATABLE_ATTRIBUTES =
%w(title feed_url url last_modified etag).freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#etagObject

Returns the value of attribute etag



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

def etag
  @etag
end

#last_modifiedObject



41
42
43
44
45
46
47
# File 'lib/feedjira/feed_utilities.rb', line 41

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

#new_entriesObject



53
54
55
# File 'lib/feedjira/feed_utilities.rb', line 53

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/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

#new_entries?Boolean

Returns:

  • (Boolean)


57
58
59
# File 'lib/feedjira/feed_utilities.rb', line 57

def new_entries?
  !new_entries.empty?
end

#sanitize_entries!Object



84
85
86
# File 'lib/feedjira/feed_utilities.rb', line 84

def sanitize_entries!
  entries.each(&:sanitize!)
end

#update_attribute(feed, name) ⇒ Object



72
73
74
75
76
77
78
79
80
81
82
# File 'lib/feedjira/feed_utilities.rb', line 72

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

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

#update_from_feed(feed) ⇒ Object



61
62
63
64
65
66
67
68
69
70
# File 'lib/feedjira/feed_utilities.rb', line 61

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

Returns:

  • (Boolean)


49
50
51
# File 'lib/feedjira/feed_utilities.rb', line 49

def updated?
  @updated || false
end