yarss 0.0.2 → 0.0.3
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.
- checksums.yaml +4 -4
- data/README.md +9 -5
- data/lib/yarss/atom/item_parser.rb +10 -0
- data/lib/yarss/attribute.rb +26 -0
- data/lib/yarss/item.rb +7 -1
- data/lib/yarss/rdf/item_parser.rb +18 -0
- data/lib/yarss/rss/item_parser.rb +20 -0
- data/lib/yarss/version.rb +1 -1
- data/lib/yarss.rb +36 -12
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f5fc31207ee7282e79e3f9d031087d1c77e8dba7
|
4
|
+
data.tar.gz: 0e06a204c7c09a60c6c9ea09666b1aebe6a82d2a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d2c85c04789c1e6864756f26bd5951ba92475dea47f228b78f09c2300e0f719c00042a198a5c515855aee9b275f3cf64bd4154d506a2485247b6f224c10136da
|
7
|
+
data.tar.gz: 581178f47cc9542e111f2211ecf79e05961657807f8cf92c4a4fe5a94e3be46db2e601d3b9095c4a7be5634665b2f157c14418914780933051099480d75a7dee
|
data/README.md
CHANGED
@@ -12,13 +12,17 @@ the fastest XML parser I know of. JRuby users should probably use
|
|
12
12
|
|
13
13
|
```ruby
|
14
14
|
['path/to/feed.rss', 'path/to/feed.atom', 'path/to/feed.rdf'].each do |file_path|
|
15
|
-
feed
|
16
|
-
|
17
|
-
|
15
|
+
feed.title # => "Foo's bars"
|
16
|
+
feed.link # => 'http://foo.bar/'
|
17
|
+
feed.description # => 'Bars everywhere!'
|
18
18
|
|
19
19
|
feed.items.each do |item|
|
20
|
-
|
21
|
-
|
20
|
+
item.id # => 'id'
|
21
|
+
item.title # => 'Hello!'
|
22
|
+
item.updated_at # => #<DateTIme ...>
|
23
|
+
item.link # => 'http://foo.bar/1'
|
24
|
+
item.author # => 'Joe'
|
25
|
+
item.content # => '<p>Hi!</p>'
|
22
26
|
end
|
23
27
|
end
|
24
28
|
```
|
@@ -28,6 +28,7 @@ module Yarss
|
|
28
28
|
title: title,
|
29
29
|
updated_at: updated,
|
30
30
|
link: link,
|
31
|
+
author: author,
|
31
32
|
content: content
|
32
33
|
)
|
33
34
|
end
|
@@ -76,6 +77,15 @@ module Yarss
|
|
76
77
|
raise ParseError, e
|
77
78
|
end
|
78
79
|
|
80
|
+
# Extract the author.
|
81
|
+
#
|
82
|
+
# @raise [ParseError] If not found.
|
83
|
+
#
|
84
|
+
# @return [String]
|
85
|
+
def author
|
86
|
+
Attribute.author_value(data['author'] || '')
|
87
|
+
end
|
88
|
+
|
79
89
|
# Extract the content.
|
80
90
|
#
|
81
91
|
# @return [String]
|
data/lib/yarss/attribute.rb
CHANGED
@@ -30,6 +30,32 @@ module Yarss
|
|
30
30
|
raise ParseError, e
|
31
31
|
end
|
32
32
|
|
33
|
+
# Extract a +String+ value from a given author attribute.
|
34
|
+
#
|
35
|
+
# @raise [ParseError] If type of value is not known.
|
36
|
+
#
|
37
|
+
# @example
|
38
|
+
# Yarss::Attribute.author_value('Foo') # => 'Foo'
|
39
|
+
# Yarss::Attribute.author_value('name' => 'Foo') # => 'Foo'
|
40
|
+
#
|
41
|
+
# @param value [String, Hash] An attribute.
|
42
|
+
#
|
43
|
+
# @return [String]
|
44
|
+
def self.author_value(value)
|
45
|
+
value ||= ''
|
46
|
+
|
47
|
+
case value
|
48
|
+
when Hash
|
49
|
+
value(value.fetch('name'))
|
50
|
+
when String
|
51
|
+
value.strip
|
52
|
+
else
|
53
|
+
raise ParseError, "Unknown #{value.class} attribute: #{value.inspect}"
|
54
|
+
end
|
55
|
+
rescue KeyError => e
|
56
|
+
raise ParseError, e
|
57
|
+
end
|
58
|
+
|
33
59
|
# Extract a +String+ value from a given link attribute.
|
34
60
|
#
|
35
61
|
# @raise [ParseError] If type of value is not known or no link is found.
|
data/lib/yarss/item.rb
CHANGED
@@ -23,6 +23,11 @@ module Yarss
|
|
23
23
|
# @return [String]
|
24
24
|
attr_accessor :link
|
25
25
|
|
26
|
+
# Author.
|
27
|
+
#
|
28
|
+
# @return [String]
|
29
|
+
attr_accessor :author
|
30
|
+
|
26
31
|
# Content.
|
27
32
|
#
|
28
33
|
# @return [String]
|
@@ -41,13 +46,14 @@ module Yarss
|
|
41
46
|
# @param other [Item]
|
42
47
|
#
|
43
48
|
# @return [Bool]
|
44
|
-
def ==(other)
|
49
|
+
def ==(other)
|
45
50
|
return false unless other.is_a?(self.class)
|
46
51
|
|
47
52
|
id == other.id &&
|
48
53
|
title == other.title &&
|
49
54
|
updated_at == other.updated_at &&
|
50
55
|
link == other.link &&
|
56
|
+
author == other.author &&
|
51
57
|
content == other.content
|
52
58
|
end
|
53
59
|
end
|
@@ -26,6 +26,7 @@ module Yarss
|
|
26
26
|
title: title,
|
27
27
|
updated_at: updated,
|
28
28
|
link: link,
|
29
|
+
author: author,
|
29
30
|
content: description
|
30
31
|
)
|
31
32
|
end
|
@@ -83,6 +84,23 @@ module Yarss
|
|
83
84
|
raise ParseError, e
|
84
85
|
end
|
85
86
|
|
87
|
+
# Extract the author.
|
88
|
+
#
|
89
|
+
# @raise [ParseError] If not found.
|
90
|
+
#
|
91
|
+
# @return [String]
|
92
|
+
def author
|
93
|
+
author = if data['dc:creator']
|
94
|
+
data['dc:creator']
|
95
|
+
else
|
96
|
+
data.fetch('creator')
|
97
|
+
end
|
98
|
+
|
99
|
+
Attribute.value(author)
|
100
|
+
rescue KeyError => e
|
101
|
+
raise ParseError, e
|
102
|
+
end
|
103
|
+
|
86
104
|
# Extract the description.
|
87
105
|
#
|
88
106
|
# @return [String]
|
@@ -28,6 +28,7 @@ module Yarss
|
|
28
28
|
title: title,
|
29
29
|
updated_at: pub_date,
|
30
30
|
link: link,
|
31
|
+
author: author,
|
31
32
|
content: description
|
32
33
|
)
|
33
34
|
end
|
@@ -78,6 +79,25 @@ module Yarss
|
|
78
79
|
raise ParseError, e
|
79
80
|
end
|
80
81
|
|
82
|
+
# Extract the author.
|
83
|
+
#
|
84
|
+
# @raise [ParseError] If not found.
|
85
|
+
#
|
86
|
+
# @return [String]
|
87
|
+
def author
|
88
|
+
author = if data['dc:creator']
|
89
|
+
data['dc:creator']
|
90
|
+
elsif data['creator']
|
91
|
+
data['creator']
|
92
|
+
elsif data['author']
|
93
|
+
data['author']
|
94
|
+
else
|
95
|
+
''
|
96
|
+
end
|
97
|
+
|
98
|
+
Attribute.value(author)
|
99
|
+
end
|
100
|
+
|
81
101
|
# Extract the content.
|
82
102
|
#
|
83
103
|
# @return [String]
|
data/lib/yarss/version.rb
CHANGED
data/lib/yarss.rb
CHANGED
@@ -31,11 +31,17 @@ module Yarss
|
|
31
31
|
# @example
|
32
32
|
# feed = Yarss.new('path/to/feed.rss')
|
33
33
|
#
|
34
|
-
#
|
34
|
+
# feed.title # => "Foo's bars"
|
35
|
+
# feed.link # => 'http://foo.bar/'
|
36
|
+
# feed.description # => 'Bars everywhere!'
|
35
37
|
#
|
36
38
|
# feed.items.each do |item|
|
37
|
-
#
|
38
|
-
#
|
39
|
+
# item.id # => 'id'
|
40
|
+
# item.title # => 'Hello!'
|
41
|
+
# item.updated_at # => #<DateTIme ...>
|
42
|
+
# item.link # => 'http://foo.bar/1'
|
43
|
+
# item.author # => 'Joe'
|
44
|
+
# item.content # => '<p>Hi!</p>'
|
39
45
|
# end
|
40
46
|
#
|
41
47
|
# @return [Feed]
|
@@ -58,11 +64,17 @@ module Yarss
|
|
58
64
|
# feed = Yarss.from_io(Pathname.new('path/to/feed.rss'))
|
59
65
|
# feed = Yarss.from_io(File.open('path/to/feed.rss', 'rb'))
|
60
66
|
#
|
61
|
-
#
|
67
|
+
# feed.title # => "Foo's bars"
|
68
|
+
# feed.link # => 'http://foo.bar/'
|
69
|
+
# feed.description # => 'Bars everywhere!'
|
62
70
|
#
|
63
71
|
# feed.items.each do |item|
|
64
|
-
#
|
65
|
-
#
|
72
|
+
# item.id # => 'id'
|
73
|
+
# item.title # => 'Hello!'
|
74
|
+
# item.updated_at # => #<DateTIme ...>
|
75
|
+
# item.link # => 'http://foo.bar/1'
|
76
|
+
# item.author # => 'Joe'
|
77
|
+
# item.content # => '<p>Hi!</p>'
|
66
78
|
# end
|
67
79
|
#
|
68
80
|
# @return [Feed]
|
@@ -81,11 +93,17 @@ module Yarss
|
|
81
93
|
# @example
|
82
94
|
# feed = Yarss.from_file('path/to/feed.rss')
|
83
95
|
#
|
84
|
-
#
|
96
|
+
# feed.title # => "Foo's bars"
|
97
|
+
# feed.link # => 'http://foo.bar/'
|
98
|
+
# feed.description # => 'Bars everywhere!'
|
85
99
|
#
|
86
100
|
# feed.items.each do |item|
|
87
|
-
#
|
88
|
-
#
|
101
|
+
# item.id # => 'id'
|
102
|
+
# item.title # => 'Hello!'
|
103
|
+
# item.updated_at # => #<DateTIme ...>
|
104
|
+
# item.link # => 'http://foo.bar/1'
|
105
|
+
# item.author # => 'Joe'
|
106
|
+
# item.content # => '<p>Hi!</p>'
|
89
107
|
# end
|
90
108
|
#
|
91
109
|
# @return [Feed]
|
@@ -105,11 +123,17 @@ module Yarss
|
|
105
123
|
# @example
|
106
124
|
# feed = Yarss.from_string('...)
|
107
125
|
#
|
108
|
-
#
|
126
|
+
# feed.title # => "Foo's bars"
|
127
|
+
# feed.link # => 'http://foo.bar/'
|
128
|
+
# feed.description # => 'Bars everywhere!'
|
109
129
|
#
|
110
130
|
# feed.items.each do |item|
|
111
|
-
#
|
112
|
-
#
|
131
|
+
# item.id # => 'id'
|
132
|
+
# item.title # => 'Hello!'
|
133
|
+
# item.updated_at # => #<DateTIme ...>
|
134
|
+
# item.link # => 'http://foo.bar/1'
|
135
|
+
# item.author # => 'Joe'
|
136
|
+
# item.content # => '<p>Hi!</p>'
|
113
137
|
# end
|
114
138
|
#
|
115
139
|
# @return [Feed]
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yarss
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Oldrich Vetesnik
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-02-
|
11
|
+
date: 2016-02-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|