Class: Screencap::Fetcher

Inherits:
Object
  • Object
show all
Defined in:
lib/screencap/fetcher.rb

Instance Method Summary collapse

Constructor Details

#initialize(url) ⇒ Fetcher

Returns a new instance of Fetcher.



3
4
5
# File 'lib/screencap/fetcher.rb', line 3

def initialize(url)
  @url = url
end

Instance Method Details

#clean_filenameObject



27
28
29
# File 'lib/screencap/fetcher.rb', line 27

def clean_filename
  "#{@url.delete('/.:?!')}.png"
end

#fetch(opts = {}) ⇒ Object



7
8
9
10
11
# File 'lib/screencap/fetcher.rb', line 7

def fetch(opts = {})
  @filename = opts.fetch(:output, clean_filename)
  raster(@url, @filename, opts)
  fetched_file
end

#fetched_fileObject



17
18
19
20
21
# File 'lib/screencap/fetcher.rb', line 17

def fetched_file
  if File.exists?(filename)
    File.open(filename)
  end
end

#filenameObject



13
14
15
# File 'lib/screencap/fetcher.rb', line 13

def filename
  @filename
end

#raster(*args) ⇒ Object



23
24
25
# File 'lib/screencap/fetcher.rb', line 23

def raster(*args)
  Screencap::Phantom.rasterize(*args)
end