Class: YAMG::Screenshot
- Inherits:
-
Object
- Object
- YAMG::Screenshot
- Defined in:
- lib/yamg/screenshot.rb
Overview
Screenshot from multiple providers
Instance Attribute Summary collapse
-
#command ⇒ Object
Returns the value of attribute command.
-
#size ⇒ Object
Returns the value of attribute size.
-
#url ⇒ Object
Returns the value of attribute url.
Instance Method Summary collapse
- #android ⇒ Object
-
#initialize(*ss) ⇒ Screenshot
constructor
Uses PhantomJS.
-
#work(path) ⇒ Object
Take the screenshot Do we need pixel depth??.
Constructor Details
#initialize(*ss) ⇒ Screenshot
Uses PhantomJS
9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/yamg/screenshot.rb', line 9 def initialize(*ss) @name, opts = ss raise 'No screen size provided' unless opts && opts['size'] uri = URI.parse(opts['url']) @url = "http://#{uri}" @size = opts['size'] @size = @size.split(/\s?,\s?/) if @size.respond_to?(:split) @dpi = @size.pop if @size.length > 2 @dpi ||= opts['dpi'] @fetcher = Screencap::Fetcher.new(@url) end |
Instance Attribute Details
#command ⇒ Object
Returns the value of attribute command.
6 7 8 |
# File 'lib/yamg/screenshot.rb', line 6 def command @command end |
#size ⇒ Object
Returns the value of attribute size.
6 7 8 |
# File 'lib/yamg/screenshot.rb', line 6 def size @size end |
#url ⇒ Object
Returns the value of attribute url.
6 7 8 |
# File 'lib/yamg/screenshot.rb', line 6 def url @url end |
Instance Method Details
#android ⇒ Object
21 22 23 |
# File 'lib/yamg/screenshot.rb', line 21 def android # adb -e shell screencap -p | perl -pe 's/\x0D\x0A/\x0A/g' > screen.png end |
#work(path) ⇒ Object
Take the screenshot Do we need pixel depth??
27 28 29 30 31 32 |
# File 'lib/yamg/screenshot.rb', line 27 def work(path) out = "#{path}/#{@name}.png" @fetcher.fetch(output: out, width: @size[0], height: @size[1], dpi: @dpi) rescue Screencap::Error puts "Fail to capture screenshot #{@url}" end |