yarss 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cb088fb3631b5463bb8927d313274cf60231cc77
4
- data.tar.gz: 3d32d941a069626c5ca40095aa94141d336e2ca8
3
+ metadata.gz: f5fc31207ee7282e79e3f9d031087d1c77e8dba7
4
+ data.tar.gz: 0e06a204c7c09a60c6c9ea09666b1aebe6a82d2a
5
5
  SHA512:
6
- metadata.gz: cd09570af97b5d8abe25d824293b5a7d5bd08411b6e8e968d9fe72ea274ae4e08f42066a49f6507245f714a8321775bd7e503ed26522557b541c4a1ae58b676e
7
- data.tar.gz: 7ed021d0ec037c09e6e19fbb023450f9d8b8e36ad0d23236e38fca69cc1876acb2db6ae0da88aa97a129e993168ffee464982f2fd04e7ad3a319f87cd64d29b5
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 = Yarss.new(file_path)
16
-
17
- puts "#{feed.title}, #{feed.link}, #{feed.description}"
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
- puts "#{item.id}, #{item.title}, #{item.updated_at}, #{item.link}"
21
- puts item.content
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]
@@ -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) # rubocop:disable Metrics/AbcSize
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
@@ -2,5 +2,5 @@
2
2
 
3
3
  module Yarss
4
4
  # Version number, happy now?
5
- VERSION = '0.0.2'
5
+ VERSION = '0.0.3'
6
6
  end
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
- # puts "#{feed.title}, #{feed.link}, #{feed.description}"
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
- # puts "#{item.id}, #{item.title}, #{item.updated_at}, #{item.link}"
38
- # puts item.content
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
- # puts "#{feed.title}, #{feed.link}, #{feed.description}"
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
- # puts "#{item.id}, #{item.title}, #{item.updated_at}, #{item.link}"
65
- # puts item.content
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
- # puts "#{feed.title}, #{feed.link}, #{feed.description}"
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
- # puts "#{item.id}, #{item.title}, #{item.updated_at}, #{item.link}"
88
- # puts item.content
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
- # puts "#{feed.title}, #{feed.link}, #{feed.description}"
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
- # puts "#{item.id}, #{item.title}, #{item.updated_at}, #{item.link}"
112
- # puts item.content
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.2
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-04 00:00:00.000000000 Z
11
+ date: 2016-02-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler