Class: Downer::StrategyFinder
- Inherits:
-
Object
- Object
- Downer::StrategyFinder
- Defined in:
- lib/downer/download_strategy.rb
Class Method Summary collapse
-
.find_strategy(url_source, options = {}) ⇒ Object
Determines a strategy for extracting urls from a media type.
-
.is_local_file?(url_source) ⇒ Boolean
Determine whether the source is located on a local file system.
-
.is_remote_source?(url_source) ⇒ Boolean
Determine if this is something that lives online.
Class Method Details
.find_strategy(url_source, options = {}) ⇒ Object
Determines a strategy for extracting urls from a media type
7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/downer/download_strategy.rb', line 7 def find_strategy(url_source, ={}) strategy = nil if is_local_file?(url_source) strategy = DownloadStrategy::FlatFileStrategy.new(url_source, ) elsif is_remote_source?(url_source) strategy = DownloadStrategy::WebsiteStrategy.new(url_source, ) else raise "Could not find strategy" end strategy end |
.is_local_file?(url_source) ⇒ Boolean
Determine whether the source is located on a local file system
21 22 23 |
# File 'lib/downer/download_strategy.rb', line 21 def is_local_file?(url_source) File.exist?(url_source) end |
.is_remote_source?(url_source) ⇒ Boolean
Determine if this is something that lives online
26 27 28 29 |
# File 'lib/downer/download_strategy.rb', line 26 def is_remote_source?(url_source) #if url_source =~ /(ftp|https?).*$/ url_source.match(/(ftp|https?).*$/) ? true : false end |