Class: Captureit::Capture

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

Constant Summary collapse

IMAGEEXTENSIONS =

Valid image formats

%w{png jpeg jpg}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url, options = {}) ⇒ Capture



25
26
27
28
29
30
31
# File 'lib/captureit.rb', line 25

def initialize(url, options = {})
  @url = url
  @folder = options[:folder] || Dir.pwd
  @filename = options[:filename] || "captureit.jpeg"
  @cutycapt_path = options[:cutycapt_path] || find_cutycapt_path('cutycapt')
  validate_extension?(@filename)
end

Instance Attribute Details

#cutycapt_pathObject

Returns the value of attribute cutycapt_path.



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

def cutycapt_path
  @cutycapt_path
end

#filenameObject

Returns the value of attribute filename.



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

def filename
  @filename
end

#folderObject

Returns the value of attribute folder.



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

def folder
  @folder
end

#resultObject

Returns the value of attribute result.



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

def result
  @result
end

#urlObject

Returns the value of attribute url.



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

def url
  @url
end

Instance Method Details

#captureObject



33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/captureit.rb', line 33

def capture
  cmd = "#{@cutycapt_path} --url='#{@url}' --out='#{@folder}/#{@filename}'"

  `#{cmd}`

  if captured_file_exists?
    @result = expected_captured_path
  else
    @result = nil
  end
  
  @result
end

#validate_extension?(filename) ⇒ Boolean



47
48
49
# File 'lib/captureit.rb', line 47

def validate_extension?(filename)
  raise InvalidExtensionError, "Invalid extension!" unless IMAGEEXTENSIONS.include? filename.split('.').last
end