123456789_123456789_123456789_123456789_123456789_

Class: Selenium::WebDriver::PrintOptions

Relationships & Source Files
Inherits: Object
Defined in: rb/lib/selenium/webdriver/common/print_options.rb

Overview

Represents options for printing a page.

Constant Summary

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.newPrintOptions

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/common/print_options.rb', line 31
def initialize
  @orientation = DEFAULT_ORIENTATION
  @scale = DEFAULT_SCALE
  @background = false
  @page_ranges = nil
  @page_size = DEFAULT_PAGE_SIZE
  @margins = DEFAULT_MARGINS
end

Instance Attribute Details

#background (rw)

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/common/print_options.rb', line 29
attr_accessor :orientation, :scale, :background, :page_ranges, :margins

#margins (rw)

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/common/print_options.rb', line 29
attr_accessor :orientation, :scale, :background, :page_ranges, :margins

#orientation (rw)

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/common/print_options.rb', line 29
attr_accessor :orientation, :scale, :background, :page_ranges, :margins

#page_ranges (rw)

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/common/print_options.rb', line 29
attr_accessor :orientation, :scale, :background, :page_ranges, :margins

#page_sizeHash (rw)

Gets the current page size.

Returns:

  • (Hash)

    The current page size hash with :width and :height.

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/common/print_options.rb', line 63
attr_reader :page_size

#page_size=(value) (rw)

Sets the page size. Can be a predefined symbol or custom size hash.

Parameters:

  • value (Symbol, Hash)

    The predefined size (:letter, :legal, :a4, :tabloid) or a custom hash.

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/common/print_options.rb', line 68
def page_size=(value)
  predefined_sizes = {
    letter: {width: 21.59, height: 27.94},
    legal: {width: 21.59, height: 35.56},
    a4: {width: 21.0, height: 29.7},
    tabloid: {width: 27.94, height: 43.18}
  }

  case value
  when Symbol
    raise ArgumentError, "Invalid page size: #{value}" unless predefined_sizes.key?(value)

    @page_size = predefined_sizes[value]
  when Hash
    unless value.key?(:width) && value.key?(:height)
      raise ArgumentError, 'Custom page size must include :width and :height'
    end

    @page_size = value
  else
    raise ArgumentError, 'Page size must be a Symbol or a Hash'
  end
end

#scale (rw)

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/common/print_options.rb', line 29
attr_accessor :orientation, :scale, :background, :page_ranges, :margins

Instance Method Details

#to_hHash

Converts the options to a hash format to be used by ::Selenium::WebDriver.

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/common/print_options.rb', line 43
def to_h
  options = {
    orientation: @orientation,
    scale: @scale,
    background: @background,
    pageRanges: @page_ranges,
    paperWidth: @page_size[:width],
    paperHeight: @page_size[:height],
    marginTop: @margins[:top],
    marginBottom: @margins[:bottom],
    marginLeft: @margins[:left],
    marginRight: @margins[:right]
  }

  options.compact
end