Class: Kernel

Inherits:
Object
  • Object
show all
Defined in:
lib/dvdprofiler2xbmc/open_cache_extension.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#html_cache_dirObject

Returns the value of attribute html_cache_dir.



4
5
6
# File 'lib/dvdprofiler2xbmc/open_cache_extension.rb', line 4

def html_cache_dir
  @html_cache_dir
end

Instance Method Details

#open_cache(url) ⇒ Object

cache any files read using http protocol



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/dvdprofiler2xbmc/open_cache_extension.rb', line 8

def open_cache(url)
  if url =~ /^https?:\/\//i
    filespec = url.gsub(/^http:\//, @html_cache_dir).gsub(/\/$/, '.html')
    begin
      fh = open(filespec)
    rescue Exception
      fh = open(url)
      cache_html_files(filespec, fh.read)
      fh.rewind
    end
  else
    fh = open(url)
  end
  fh
end