feedzirra 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,10 +1,12 @@
1
1
  module Feedzirra
2
- module FeedEntryUtilities
2
+ module FeedEntryUtilities
3
+
4
+ include Enumerable
3
5
 
4
6
  def published
5
7
  @published ||= @updated
6
8
  end
7
-
9
+
8
10
  def parse_datetime(string)
9
11
  begin
10
12
  DateTime.parse(string).feed_utils_to_gm_time
@@ -13,34 +15,51 @@ module Feedzirra
13
15
  nil
14
16
  end
15
17
  end
16
-
18
+
17
19
  ##
18
20
  # Returns the id of the entry or its url if not id is present, as some formats don't support it
19
- def id
21
+ def id
20
22
  @entry_id ||= @url
21
23
  end
22
-
24
+
23
25
  ##
24
26
  # Writer for published. By default, we keep the "oldest" publish time found.
25
- def published=(val)
27
+ def published=(val)
26
28
  parsed = parse_datetime(val)
27
- @published = parsed if !@published || parsed < @published
29
+ @published = parsed if !@published || parsed < @published
28
30
  end
29
-
31
+
30
32
  ##
31
33
  # Writer for updated. By default, we keep the most recent update time found.
32
- def updated=(val)
34
+ def updated=(val)
33
35
  parsed = parse_datetime(val)
34
36
  @updated = parsed if !@updated || parsed > @updated
35
37
  end
36
38
 
37
39
  def sanitize!
38
- self.title.sanitize! if self.title
39
- self.author.sanitize! if self.author
40
+ self.title.sanitize! if self.title
41
+ self.author.sanitize! if self.author
40
42
  self.summary.sanitize! if self.summary
41
43
  self.content.sanitize! if self.content
42
44
  end
43
-
45
+
44
46
  alias_method :last_modified, :published
47
+
48
+ def each
49
+ @rss_fields ||= self.instance_variables
50
+
51
+ @rss_fields.each do |field|
52
+ yield(field.to_s.sub('@', ''), self.instance_variable_get(field))
53
+ end
54
+ end
55
+
56
+ def [](field)
57
+ self.instance_variable_get("@#{field.to_s}")
58
+ end
59
+
60
+ def []=(field, value)
61
+ self.instance_variable_set("@#{field.to_s}", value)
62
+ end
63
+
45
64
  end
46
65
  end
@@ -5,6 +5,7 @@ module Feedzirra
5
5
  class AtomEntry
6
6
  include SAXMachine
7
7
  include FeedEntryUtilities
8
+
8
9
  element :title
9
10
  element :link, :as => :url, :value => :href, :with => {:type => "text/html", :rel => "alternate"}
10
11
  element :name, :as => :author
@@ -5,6 +5,7 @@ module Feedzirra
5
5
  class AtomFeedBurnerEntry
6
6
  include SAXMachine
7
7
  include FeedEntryUtilities
8
+
8
9
  element :title
9
10
  element :name, :as => :author
10
11
  element :link, :as => :url, :value => :href, :with => {:type => "text/html", :rel => "alternate"}
@@ -6,6 +6,7 @@ module Feedzirra
6
6
  class ITunesRSSItem
7
7
  include SAXMachine
8
8
  include FeedEntryUtilities
9
+
9
10
  element :author
10
11
  element :guid
11
12
  element :title
@@ -3,7 +3,6 @@ module Feedzirra
3
3
  module Parser
4
4
  # Parser for dealing with RDF feed entries.
5
5
  class RSSEntry
6
- include Enumerable
7
6
  include SAXMachine
8
7
  include FeedEntryUtilities
9
8
 
@@ -28,21 +27,6 @@ module Feedzirra
28
27
 
29
28
  element :guid, :as => :entry_id
30
29
 
31
- def each
32
- @rss_fields ||= self.instance_variables
33
-
34
- @rss_fields.each do |field|
35
- yield(field.to_s.sub('@', ''), self.instance_variable_get(field))
36
- end
37
- end
38
-
39
- def [](field)
40
- self.instance_variable_get("@#{field.to_s}")
41
- end
42
-
43
- def []=(field, value)
44
- self.instance_variable_set("@#{field.to_s}", value)
45
- end
46
30
  end
47
31
 
48
32
  end
@@ -1,3 +1,3 @@
1
1
  module Feedzirra
2
- VERSION = '0.1.0'
2
+ VERSION = '0.1.1'
3
3
  end
@@ -6,31 +6,31 @@ describe Feedzirra::Parser::AtomEntry do
6
6
  # but this is actually how it should work. You would never just pass entry xml straight to the AtomEnry
7
7
  @entry = Feedzirra::Parser::Atom.parse(sample_atom_feed).entries.first
8
8
  end
9
-
9
+
10
10
  it "should parse the title" do
11
11
  @entry.title.should == "AWS Job: Architect & Designer Position in Turkey"
12
12
  end
13
-
13
+
14
14
  it "should parse the url" do
15
15
  @entry.url.should == "http://aws.typepad.com/aws/2009/01/aws-job-architect-designer-position-in-turkey.html"
16
16
  end
17
-
17
+
18
18
  it "should parse the url even when" do
19
19
  Feedzirra::Parser::Atom.parse(load_sample("atom_with_link_tag_for_url_unmarked.xml")).entries.first.url.should == "http://www.innoq.com/blog/phaus/2009/07/ja.html"
20
20
  end
21
-
21
+
22
22
  it "should parse the author" do
23
23
  @entry.author.should == "AWS Editor"
24
24
  end
25
-
25
+
26
26
  it "should parse the content" do
27
27
  @entry.content.should == sample_atom_entry_content
28
28
  end
29
-
29
+
30
30
  it "should provide a summary" do
31
31
  @entry.summary.should == "Late last year an entrepreneur from Turkey visited me at Amazon HQ in Seattle. We talked about his plans to use AWS as part of his new social video portal startup. I won't spill any beans before he's ready to..."
32
32
  end
33
-
33
+
34
34
  it "should parse the published date" do
35
35
  @entry.published.to_s.should == "Fri Jan 16 18:21:00 UTC 2009"
36
36
  end
@@ -38,12 +38,49 @@ describe Feedzirra::Parser::AtomEntry do
38
38
  it "should parse the categories" do
39
39
  @entry.categories.should == ['Turkey', 'Seattle']
40
40
  end
41
-
41
+
42
42
  it "should parse the updated date" do
43
43
  @entry.updated.to_s.should == "Fri Jan 16 18:21:00 UTC 2009"
44
44
  end
45
-
45
+
46
46
  it "should parse the id" do
47
47
  @entry.id.should == "tag:typepad.com,2003:post-61484736"
48
48
  end
49
+
50
+ it "should support each" do
51
+ @entry.respond_to? :each
52
+ end
53
+
54
+ it "should be able to list out all fields with each" do
55
+ all_fields = []
56
+ @entry.each do |field, value|
57
+ all_fields << field
58
+ end
59
+ all_fields.sort == ['author', 'categories', 'content', 'id', 'published', 'summary', 'title', 'url']
60
+ end
61
+
62
+ it "should be able to list out all values with each" do
63
+ title_value = ''
64
+ @entry.each do |field, value|
65
+ title_value = value if field == 'title'
66
+ end
67
+ title_value.should == "AWS Job: Architect & Designer Position in Turkey"
68
+ end
69
+
70
+ it "should support checking if a field exists in the entry" do
71
+ @entry.include?('title') && @entry.include?('author')
72
+ end
73
+
74
+ it "should allow access to fields with hash syntax" do
75
+ @entry['title'] == @entry.title
76
+ @entry['title'].should == "AWS Job: Architect & Designer Position in Turkey"
77
+ @entry['author'] == @entry.author
78
+ @entry['author'].should == "AWS Editor"
79
+ end
80
+
81
+ it "should allow setting field values with hash syntax" do
82
+ @entry['title'] = "Foobar"
83
+ @entry.title.should == "Foobar"
84
+ end
85
+
49
86
  end
@@ -14,35 +14,35 @@ describe Feedzirra::Parser::RSSEntry do
14
14
  @entry.title = Feedzirra::Parser::RSS.parse(sample_rss_feed).entries.first.title
15
15
  end
16
16
  end
17
-
17
+
18
18
  it "should parse the title" do
19
19
  @entry.title.should == "Nokogiri’s Slop Feature"
20
20
  end
21
-
21
+
22
22
  it "should parse the url" do
23
23
  @entry.url.should == "http://tenderlovemaking.com/2008/12/04/nokogiris-slop-feature/"
24
24
  end
25
-
25
+
26
26
  it "should parse the author" do
27
27
  @entry.author.should == "Aaron Patterson"
28
28
  end
29
-
29
+
30
30
  it "should parse the content" do
31
31
  @entry.content.should == sample_rss_entry_content
32
32
  end
33
-
33
+
34
34
  it "should provide a summary" do
35
35
  @entry.summary.should == "Oops! When I released nokogiri version 1.0.7, I totally forgot to talk about Nokogiri::Slop() feature that was added. Why is it called \"slop\"? It lets you sloppily explore documents. Basically, it decorates your document with method_missing() that allows you to search your document via method calls.\nGiven this document:\n\ndoc = Nokogiri::Slop&#40;&#60;&#60;-eohtml&#41;\n&#60;html&#62;\n&#160; &#60;body&#62;\n&#160; [...]"
36
36
  end
37
-
38
- it "should parse the published date" do
37
+
38
+ it "should parse the published date" do
39
39
  @entry.published.to_s.should == "Thu Dec 04 17:17:49 UTC 2008"
40
40
  end
41
41
 
42
42
  it "should parse the categories" do
43
43
  @entry.categories.should == ['computadora', 'nokogiri', 'rails']
44
44
  end
45
-
45
+
46
46
  it "should parse the guid as id" do
47
47
  @entry.id.should == "http://tenderlovemaking.com/?p=198"
48
48
  end
@@ -54,7 +54,7 @@ describe Feedzirra::Parser::RSSEntry do
54
54
  it "should be able to list out all fields with each" do
55
55
  all_fields = []
56
56
  @entry.each do |field, value|
57
- all_fields << field
57
+ all_fields << field
58
58
  end
59
59
  all_fields.sort == ['author', 'categories', 'content', 'id', 'published', 'summary', 'title', 'url']
60
60
  end
@@ -72,12 +72,12 @@ describe Feedzirra::Parser::RSSEntry do
72
72
  end
73
73
 
74
74
  it "should allow access to fields with hash syntax" do
75
- @entry['title'] == @entry.title && \
76
- @entry['title'].should == "Nokogiri’s Slop Feature" && \
77
- @entry['author'] == @entry.author && \
78
- @entry['author'].should == "Aaron Patterson"
75
+ @entry['title'] == @entry.title
76
+ @entry['title'].should == "Nokogiri’s Slop Feature"
77
+ @entry['author'] == @entry.author
78
+ @entry['author'].should == "Aaron Patterson"
79
79
  end
80
-
80
+
81
81
  it "should allow setting field values with hash syntax" do
82
82
  @entry['title'] = "Foobar"
83
83
  @entry.title.should == "Foobar"
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: feedzirra
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 0
10
- version: 0.1.0
9
+ - 1
10
+ version: 0.1.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Paul Dix