feedzirra 0.0.19 → 0.0.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/lib/feedzirra.rb CHANGED
@@ -30,5 +30,5 @@ require 'feedzirra/parser/atom'
30
30
  require 'feedzirra/parser/atom_feed_burner'
31
31
 
32
32
  module Feedzirra
33
- VERSION = "0.0.19"
33
+ VERSION = "0.0.20"
34
34
  end
@@ -1,7 +1,7 @@
1
1
  module Feedzirra
2
2
  module FeedUtilities
3
- UPDATABLE_ATTRIBUTES = %w(title feed_url url last_modified)
4
-
3
+ UPDATABLE_ATTRIBUTES = %w(title feed_url url last_modified etag)
4
+
5
5
  attr_writer :new_entries, :updated, :last_modified
6
6
  attr_accessor :etag
7
7
 
@@ -11,50 +11,50 @@ module Feedzirra
11
11
  entry ? entry.published : nil
12
12
  end
13
13
  end
14
-
14
+
15
15
  def updated?
16
16
  @updated
17
17
  end
18
-
18
+
19
19
  def new_entries
20
20
  @new_entries ||= []
21
21
  end
22
-
22
+
23
23
  def has_new_entries?
24
24
  new_entries.size > 0
25
25
  end
26
-
26
+
27
27
  def update_from_feed(feed)
28
28
  self.new_entries += find_new_entries_for(feed)
29
29
  self.entries.unshift(*self.new_entries)
30
-
31
- updated! if UPDATABLE_ATTRIBUTES.any? { |name| update_attribute(feed, name) }
30
+
31
+ @updated = false
32
+ UPDATABLE_ATTRIBUTES.each do |name|
33
+ @updated ||= update_attribute(feed, name)
34
+ end
32
35
  end
33
-
36
+
34
37
  def update_attribute(feed, name)
35
38
  old_value, new_value = send(name), feed.send(name)
36
-
39
+
37
40
  if old_value != new_value
38
41
  send("#{name}=", new_value)
39
42
  end
40
43
  end
41
-
44
+
42
45
  def sanitize_entries!
43
46
  entries.each {|entry| entry.sanitize!}
44
47
  end
45
-
48
+
46
49
  private
47
-
48
- def updated!
49
- @updated = true
50
- end
51
-
50
+
52
51
  def find_new_entries_for(feed)
53
52
  # this implementation is a hack, which is why it's so ugly.
54
53
  # it's to get around the fact that not all feeds have a published date.
55
54
  # however, they're always ordered with the newest one first.
56
55
  # So we go through the entries just parsed and insert each one as a new entry
57
56
  # until we get to one that has the same url as the the newest for the feed
57
+ return feed.entries if self.entries.length == 0
58
58
  latest_entry = self.entries.first
59
59
  found_new_entries = []
60
60
  feed.entries.each do |entry|
@@ -63,7 +63,7 @@ module Feedzirra
63
63
  end
64
64
  found_new_entries
65
65
  end
66
-
66
+
67
67
  def existing_entry?(test_entry)
68
68
  entries.any? { |entry| entry.url == test_entry.url }
69
69
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: feedzirra
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.19
4
+ version: 0.0.20
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paul Dix