Class: Perus::Pinger::Screenshot
- Defined in:
- lib/perus/pinger/metrics/screenshot.rb
Instance Attribute Summary
Attributes inherited from Command
Instance Method Summary collapse
Methods inherited from Command
abstract!, abstract?, #darwin?, description, human_name, inherited, #initialize, metric!, metric?, option, options, #shell, subclasses
Constructor Details
This class inherits a constructor from Perus::Pinger::Command
Instance Method Details
#cleanup ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/perus/pinger/metrics/screenshot.rb', line 34 def cleanup unless @screenshot_file.nil? || @screenshot_file.closed? @screenshot_file.close end File.delete(.path) end |
#run ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/perus/pinger/metrics/screenshot.rb', line 11 def run if darwin? if .resize[-1] != '%' raise 'Non percent resize option unsupported by OS X currently' else percent = .resize.to_f / 100 end shell("screencapture -m -t jpg -x #{.path}") width = shell("sips -g pixelWidth #{.path}").match(/pixelWidth: (\d+)/)[1] height = shell("sips -g pixelHeight #{.path}").match(/pixelHeight: (\d+)/)[1] # sips helpfully prints data to stderr, so it's run with # backticks to avoid thowing an exception on success `sips -z #{height.to_i * percent} #{width.to_i * percent} #{.path}` else shell("export DISPLAY=:0; import -window root -resize #{.resize} #{.path}") end @screenshot_file = File.new(.path) {screenshot: @screenshot_file} end |