Class: Hootenanny::Feed
- Inherits:
-
Object
show all
- Defined in:
- lib/hootenanny/feed.rb,
lib/hootenanny/errors.rb,
lib/hootenanny/feed/file.rb,
lib/hootenanny/feed/rss_feed.rb,
lib/hootenanny/feed/atom_feed.rb,
lib/hootenanny/feed/feed_item.rb,
lib/hootenanny/feed/json_feed.rb,
lib/hootenanny/feed/null_feed.rb,
lib/hootenanny/feed/digest_feed.rb,
lib/hootenanny/feed/rss_feed_item.rb,
lib/hootenanny/feed/atom_feed_item.rb,
lib/hootenanny/feed/json_feed_item.rb,
lib/hootenanny/feed/digest_feed_item.rb
Defined Under Namespace
Classes: AtomFeed, AtomFeedItem, CombinationError, DigestFeed, DigestFeedItem, FeedItem, File, JSONFeed, JSONFeedItem, NullFeed, ParseError, RSSFeed, RSSFeedItem, UnknownContentTypeError
Constant Summary
collapse
- FEED_TYPE_MAPPINGS =
{
:rss => 'RSS',
:json => 'JSON',
:atom => 'Atom',
:digest => 'Digest',
:'' => 'Null',
}
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.from_content(content) ⇒ Object
27
28
29
30
31
32
33
|
# File 'lib/hootenanny/feed.rb', line 27
def self.from_content(content)
adapter = allocate
adapter.send :content=, content
adapter
end
|
.infer(content, options = {}) ⇒ Object
19
20
21
22
23
24
25
|
# File 'lib/hootenanny/feed.rb', line 19
def self.infer(content, options = {})
type = options.fetch(:type).to_s.downcase.to_sym
feed_class(type).from_content(content)
rescue KeyError => e
raise ::Hootenanny::Feed::UnknownContentTypeError.wrap(e)
end
|
Instance Method Details
#+(other) ⇒ Object
41
42
43
44
45
46
47
|
# File 'lib/hootenanny/feed.rb', line 41
def +(other)
raise Hootenanny::Feed::CombinationError unless self.class == other.class
feed = self.class.from_content(self.content)
feed.items = (self.items + other.items).uniq
feed
end
|
#-(other) ⇒ Object
35
36
37
38
39
|
# File 'lib/hootenanny/feed.rb', line 35
def -(other)
feed = self.class.from_content(self.content)
feed.items = self.items - other.items
feed
end
|
#empty? ⇒ Boolean
49
50
51
|
# File 'lib/hootenanny/feed.rb', line 49
def empty?
items.empty?
end
|
#type ⇒ Object
59
60
61
|
# File 'lib/hootenanny/feed.rb', line 59
def type
self.class.name.match(/Hootenanny::Feed::(\w+)Feed/)[1].downcase.to_sym
end
|