class FetchAndProcess::Base

Attributes

file_path[R]

Public Class Methods

add_handler(scheme, method) click to toggle source
# File lib/fetch_and_process/base.rb, line 56
def add_handler(scheme, method)
  handlers[scheme.to_sym] = method.to_sym
end
handle?(uri) click to toggle source
# File lib/fetch_and_process/base.rb, line 48
def handle?(uri)
  handlers.key? uri.scheme.to_sym
end
handler(uri) click to toggle source
# File lib/fetch_and_process/base.rb, line 52
def handler(uri)
  handlers[uri.scheme.to_sym]
end
handlers() click to toggle source
# File lib/fetch_and_process/base.rb, line 61
def self.handlers
  @handlers ||= {}
end
new(file_path) click to toggle source
# File lib/fetch_and_process/base.rb, line 10
def initialize(file_path)
  @file_path = file_path
end

Public Instance Methods

cache_location() click to toggle source
# File lib/fetch_and_process/base.rb, line 38
def cache_location
  @cache_location ||= begin
    hash = Digest::MD5.hexdigest uri.to_s
    path = "#{Dir.tmpdir}/fetch_and_process"
    Dir.mkdir(path, 0o700) unless File.exist?(path)
    "#{path}/#{hash}"
  end
end
download() click to toggle source

After handle is executed, the fetched file should exist on the path specified by `target`

# File lib/fetch_and_process/base.rb, line 24
def download
  raise FetchAndProcess::UnsupportedFileError unless uri.scheme && handle?

  send(handler)
end
handle?() click to toggle source
# File lib/fetch_and_process/base.rb, line 30
def handle?
  self.class.handle?(uri)
end
handler() click to toggle source
# File lib/fetch_and_process/base.rb, line 34
def handler
  self.class.handler(uri)
end
process() click to toggle source
# File lib/fetch_and_process/base.rb, line 18
def process
  # No action defined by default
  raise FetchAndProcess::UnimplementedFileError
end
uri() click to toggle source
# File lib/fetch_and_process/base.rb, line 14
def uri
  @uri ||= URI.parse(file_path)
end