Class: BilibiliSunday::Cacher
- Inherits:
-
Object
- Object
- BilibiliSunday::Cacher
- Defined in:
- lib/bilibili_sunday/cacher.rb
Instance Method Summary collapse
-
#initialize(dir) ⇒ Cacher
constructor
A new instance of Cacher.
- #read_url(url) ⇒ Object
Constructor Details
#initialize(dir) ⇒ Cacher
Returns a new instance of Cacher.
9 10 11 12 13 |
# File 'lib/bilibili_sunday/cacher.rb', line 9 def initialize(dir) @dir = dir FileUtils.mkdir_p(@dir) end |
Instance Method Details
#read_url(url) ⇒ Object
15 16 17 18 19 |
# File 'lib/bilibili_sunday/cacher.rb', line 15 def read_url(url) cached?(url) ? cached_content(url) : write_cache_for_url(url, open(url).read) end |