Class: Downer::StrategyFinder

Inherits:
Object
  • Object
show all
Defined in:
lib/downer/download_strategy.rb

Class Method Summary collapse

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, options ={})
  strategy = nil
          
  if is_local_file?(url_source)
    strategy = DownloadStrategy::FlatFileStrategy.new(url_source, options)
  elsif is_remote_source?(url_source)
    strategy = DownloadStrategy::WebsiteStrategy.new(url_source, options)
  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

Returns:

  • (Boolean)


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

Returns:

  • (Boolean)


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