Sha256: 3bf086eb7a4d43cedaeb0a1ff3a506b2bfc73ecb8df08c304a19fbb7625983ea

Contents?: true

Size: 923 Bytes

Versions: 4

Compression:

Stored size: 923 Bytes

Contents

module YAMG
  #
  # Screenshot from multiple providers
  #
  class Screenshot
    attr_accessor :url, :size, :command

    # Uses PhantomJS
    def initialize(*ss)
      @name, opts =  ss
      fail '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

    def android
      # adb -e shell screencap -p | perl -pe 's/\x0D\x0A/\x0A/g' > screen.png
    end

    # Take the screenshot
    # Do we need pixel depth??
    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
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
yamg-0.5.3 lib/yamg/screenshot.rb
yamg-0.5.1 lib/yamg/screenshot.rb
yamg-0.5.0 lib/yamg/screenshot.rb
yamg-0.3.8 lib/yamg/screenshot.rb