Class: Selenium::WebDriver::PrintOptions

Inherits:
Object
  • Object
show all
Defined in:
lib/selenium/webdriver/common/print_options.rb

Overview

Represents options for printing a page.

Constant Summary collapse

DEFAULT_SCALE =
1.0
DEFAULT_ORIENTATION =
'portrait'
DEFAULT_PAGE_SIZE =

A4 size in cm

{width: 21.0, height: 29.7}.freeze
DEFAULT_MARGINS =
{top: 1.0, bottom: 1.0, left: 1.0, right: 1.0}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializePrintOptions

Returns a new instance of PrintOptions.



31
32
33
34
35
36
37
38
# File '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

#backgroundObject

Returns the value of attribute background.



29
30
31
# File 'lib/selenium/webdriver/common/print_options.rb', line 29

def background
  @background
end

#marginsObject

Returns the value of attribute margins.



29
30
31
# File 'lib/selenium/webdriver/common/print_options.rb', line 29

def margins
  @margins
end

#orientationObject

Returns the value of attribute orientation.



29
30
31
# File 'lib/selenium/webdriver/common/print_options.rb', line 29

def orientation
  @orientation
end

#page_rangesObject

Returns the value of attribute page_ranges.



29
30
31
# File 'lib/selenium/webdriver/common/print_options.rb', line 29

def page_ranges
  @page_ranges
end

#page_sizeHash

Gets the current page size.

Returns:

  • (Hash)

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



63
64
65
# File 'lib/selenium/webdriver/common/print_options.rb', line 63

def page_size
  @page_size
end

#scaleObject

Returns the value of attribute scale.



29
30
31
# File 'lib/selenium/webdriver/common/print_options.rb', line 29

def scale
  @scale
end

Instance Method Details

#to_hHash

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

Returns:

  • (Hash)


43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File '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