Class: Captureit::Capture
- Inherits:
-
Object
- Object
- Captureit::Capture
- Defined in:
- lib/captureit.rb
Constant Summary collapse
- IMAGEEXTENSIONS =
Valid image formats
%w{png jpeg jpg}
Instance Attribute Summary collapse
-
#cutycapt_path ⇒ Object
Returns the value of attribute cutycapt_path.
-
#filename ⇒ Object
Returns the value of attribute filename.
-
#folder ⇒ Object
Returns the value of attribute folder.
-
#result ⇒ Object
Returns the value of attribute result.
-
#url ⇒ Object
Returns the value of attribute url.
Instance Method Summary collapse
- #capture ⇒ Object
-
#initialize(url, options = {}) ⇒ Capture
constructor
A new instance of Capture.
- #validate_extension?(filename) ⇒ Boolean
Constructor Details
#initialize(url, options = {}) ⇒ Capture
25 26 27 28 29 30 31 |
# File 'lib/captureit.rb', line 25 def initialize(url, = {}) @url = url @folder = [:folder] || Dir.pwd @filename = [:filename] || "captureit.jpeg" @cutycapt_path = [:cutycapt_path] || find_cutycapt_path('cutycapt') validate_extension?(@filename) end |
Instance Attribute Details
#cutycapt_path ⇒ Object
Returns the value of attribute cutycapt_path.
23 24 25 |
# File 'lib/captureit.rb', line 23 def cutycapt_path @cutycapt_path end |
#filename ⇒ Object
Returns the value of attribute filename.
23 24 25 |
# File 'lib/captureit.rb', line 23 def filename @filename end |
#folder ⇒ Object
Returns the value of attribute folder.
23 24 25 |
# File 'lib/captureit.rb', line 23 def folder @folder end |
#result ⇒ Object
Returns the value of attribute result.
23 24 25 |
# File 'lib/captureit.rb', line 23 def result @result end |
#url ⇒ Object
Returns the value of attribute url.
23 24 25 |
# File 'lib/captureit.rb', line 23 def url @url end |
Instance Method Details
#capture ⇒ Object
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 |