Class: FeedCache::Fetcher
- Inherits:
-
Object
- Object
- FeedCache::Fetcher
- Extended by:
- Forwardable
- Defined in:
- lib/feed_cache/fetcher.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
- #cache ⇒ Object
- #fetch ⇒ Object
-
#initialize(url, options = {}) ⇒ Fetcher
constructor
A new instance of Fetcher.
- #valid_feed? ⇒ Boolean
Constructor Details
#initialize(url, options = {}) ⇒ Fetcher
Returns a new instance of Fetcher.
16 17 18 19 20 |
# File 'lib/feed_cache/fetcher.rb', line 16 def initialize(url, = {}) raise "cache must be set with FeedCache.cache=" unless cache @url = url @options = { :expires_in => FeedCache.default_expires_in }.merge end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
8 9 10 |
# File 'lib/feed_cache/fetcher.rb', line 8 def @options end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
8 9 10 |
# File 'lib/feed_cache/fetcher.rb', line 8 def url @url end |
Instance Method Details
#fetch ⇒ Object
22 23 24 25 26 |
# File 'lib/feed_cache/fetcher.rb', line 22 def fetch @fz_feed = cache.fetch(cache_key, ) do Feedzirra::Feed.fetch_and_parse(url) end end |
#valid_feed? ⇒ Boolean
28 29 30 31 32 |
# File 'lib/feed_cache/fetcher.rb', line 28 def valid_feed? # Feedzirra returns fixnums in error conditions, so we # need to type check. @fz_feed && ! @fz_feed.is_a?(Fixnum) end |