Class: Puppeteer::Page::ScreenshotOptions
- Inherits:
- 
      Object
      
        - Object
- Puppeteer::Page::ScreenshotOptions
 
- Defined in:
- lib/puppeteer/page/screenshot_options.rb
Overview
/**
* @typedef {Object} ScreenshotOptions
* @property {string=} type
* @property {string=} path
* @property {boolean=} fullPage
* @property {{x: number, y: number, width: number, height: number}=} clip
* @property {number=} quality
* @property {boolean=} omitBackground
* @property {string=} encoding
*/
Instance Attribute Summary collapse
- 
  
    
      #clip  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    Returns the value of attribute clip. 
- 
  
    
      #encoding  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    Returns the value of attribute encoding. 
- 
  
    
      #path  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    Returns the value of attribute path. 
- 
  
    
      #quality  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    Returns the value of attribute quality. 
- 
  
    
      #type  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    Returns the value of attribute type. 
Instance Method Summary collapse
- #full_page? ⇒ Boolean
- 
  
    
      #initialize(options)  ⇒ ScreenshotOptions 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    A new instance of ScreenshotOptions. 
- #omit_background? ⇒ Boolean
Constructor Details
#initialize(options) ⇒ ScreenshotOptions
Returns a new instance of ScreenshotOptions.
| 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | # File 'lib/puppeteer/page/screenshot_options.rb', line 16 def initialize() if [:type] unless [:png, :jpeg].include?([:type].to_sym) raise ArgumentError.new("Unknown options.type value: #{[:type]}") end @type = [:type] elsif [:path] mime_types = MIME::Types.type_for([:path]) if mime_types.include?('image/png') @type = 'png' elsif mime_types.include?('image/jpeg') @type = 'jpeg' else raise ArgumentError.new("Unsupported screenshot mime type resolved: #{mime_types}, path: #{[:path]}") end end @type ||= 'png' if [:quality] unless @type == 'jpeg' raise ArgumentError.new("options.quality is unsupported for the #{@type} screenshots") end unless [:quality].is_a?(Numeric) raise ArgumentError.new("Expected options.quality to be a number but found #{[:quality].class}") end quality = [:quality].to_i unless (0..100).include?(quality) raise ArgumentError.new("Expected options.quality to be between 0 and 100 (inclusive), got #{quality}") end @quality = quality end if [:clip] && [:full_page] raise ArgumentError.new('options.clip and options.fullPage are exclusive') end # if (options.clip) { # assert(typeof options.clip.x === 'number', 'Expected options.clip.x to be a number but found ' + (typeof options.clip.x)); # assert(typeof options.clip.y === 'number', 'Expected options.clip.y to be a number but found ' + (typeof options.clip.y)); # assert(typeof options.clip.width === 'number', 'Expected options.clip.width to be a number but found ' + (typeof options.clip.width)); # assert(typeof options.clip.height === 'number', 'Expected options.clip.height to be a number but found ' + (typeof options.clip.height)); # assert(options.clip.width !== 0, 'Expected options.clip.width not to be 0.'); # assert(options.clip.height !== 0, 'Expected options.clip.height not to be 0.'); # } @path = [:path] @full_page = [:full_page] @clip = [:clip] @omit_background = [:omit_background] @encoding = [:encoding] end | 
Instance Attribute Details
#clip ⇒ Object (readonly)
Returns the value of attribute clip.
| 68 69 70 | # File 'lib/puppeteer/page/screenshot_options.rb', line 68 def clip @clip end | 
#encoding ⇒ Object (readonly)
Returns the value of attribute encoding.
| 68 69 70 | # File 'lib/puppeteer/page/screenshot_options.rb', line 68 def encoding @encoding end | 
#path ⇒ Object (readonly)
Returns the value of attribute path.
| 68 69 70 | # File 'lib/puppeteer/page/screenshot_options.rb', line 68 def path @path end | 
#quality ⇒ Object (readonly)
Returns the value of attribute quality.
| 68 69 70 | # File 'lib/puppeteer/page/screenshot_options.rb', line 68 def quality @quality end | 
#type ⇒ Object (readonly)
Returns the value of attribute type.
| 68 69 70 | # File 'lib/puppeteer/page/screenshot_options.rb', line 68 def type @type end | 
Instance Method Details
#full_page? ⇒ Boolean
| 70 71 72 | # File 'lib/puppeteer/page/screenshot_options.rb', line 70 def full_page? @full_page end | 
#omit_background? ⇒ Boolean
| 74 75 76 | # File 'lib/puppeteer/page/screenshot_options.rb', line 74 def omit_background? @omit_background end |