Class: Downlow::Fetcher
- Inherits:
-
Object
- Object
- Downlow::Fetcher
- Defined in:
- lib/downlow/fetcher.rb
Instance Attribute Summary collapse
-
#destination ⇒ Object
Returns the value of attribute destination.
-
#local_path ⇒ Object
readonly
Returns the value of attribute local_path.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#tmp_dir ⇒ Object
Returns the value of attribute tmp_dir.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Class Method Summary collapse
Instance Method Summary collapse
- #fetch ⇒ Object
- #fetched? ⇒ Boolean
-
#initialize(url, options = {}) ⇒ Fetcher
constructor
A new instance of Fetcher.
Constructor Details
#initialize(url, options = {}) ⇒ Fetcher
Returns a new instance of Fetcher.
25 26 27 28 29 30 31 32 |
# File 'lib/downlow/fetcher.rb', line 25 def initialize(url, = {}) @url = Pathname.new(url) @options = @tmp_dir = Pathname.new([:tmp_dir] || 'tmp'). + 'fetch' @tmp_dir.mkpath @destination = Pathname.new([:destination] || tmp_dir + self.url.basename ). @destination.dirname.mkpath end |
Instance Attribute Details
#destination ⇒ Object
Returns the value of attribute destination.
23 24 25 |
# File 'lib/downlow/fetcher.rb', line 23 def destination @destination end |
#local_path ⇒ Object (readonly)
Returns the value of attribute local_path.
22 23 24 |
# File 'lib/downlow/fetcher.rb', line 22 def local_path @local_path end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
22 23 24 |
# File 'lib/downlow/fetcher.rb', line 22 def @options end |
#tmp_dir ⇒ Object
Returns the value of attribute tmp_dir.
23 24 25 |
# File 'lib/downlow/fetcher.rb', line 23 def tmp_dir @tmp_dir end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
22 23 24 |
# File 'lib/downlow/fetcher.rb', line 22 def url @url end |
Class Method Details
.fetch(url, options = {}) ⇒ Object
15 16 17 18 19 20 |
# File 'lib/downlow/fetcher.rb', line 15 def self.fetch(url, = {}) klass = fetcher_for(url) fetcher = klass.new(url, ) fetcher.fetch fetcher.local_path end |
.fetcher_for(url) ⇒ Object
9 10 11 12 13 |
# File 'lib/downlow/fetcher.rb', line 9 def self.fetcher_for(url) @@handlers.each do |matcher, klass| return klass if matcher.match url end end |
.handles(which) ⇒ Object
4 5 6 7 |
# File 'lib/downlow/fetcher.rb', line 4 def self.handles(which) @@handlers ||= [] @@handlers << [which, self] end |
Instance Method Details
#fetch ⇒ Object
34 35 36 |
# File 'lib/downlow/fetcher.rb', line 34 def fetch raise "Should be overridden by subclass" end |
#fetched? ⇒ Boolean
38 39 40 |
# File 'lib/downlow/fetcher.rb', line 38 def fetched? !!@local_path end |