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
- 
    DEFAULT_MARGINS =
    
# File 'rb/lib/selenium/webdriver/common/print_options.rb', line 27{top: 1.0, bottom: 1.0, left: 1.0, right: 1.0}.freeze - 
    DEFAULT_ORIENTATION =
    
# File 'rb/lib/selenium/webdriver/common/print_options.rb', line 25'portrait' - 
    DEFAULT_PAGE_SIZE =
    # File 'rb/lib/selenium/webdriver/common/print_options.rb', line 26
A4 size in cm
{width: 21.0, height: 29.7}.freeze - 
    DEFAULT_SCALE =
    
# File 'rb/lib/selenium/webdriver/common/print_options.rb', line 241.0 
Class Method Summary
- .new ⇒ PrintOptions constructor
 
Instance Attribute Summary
- #background rw
 - #margins rw
 - #orientation rw
 - #page_ranges rw
 - 
    
      #page_size  ⇒ Hash 
    
    rw
    
Gets the current page size.
 - 
    
      #page_size=(value)  
    
    rw
    
Sets the page size.
 - #scale rw
 
Instance Method Summary
- 
    
      #to_h  ⇒ Hash 
    
    
Converts the options to a hash format to be used by
::Selenium::WebDriver. 
Constructor Details
    .new  ⇒ PrintOptions 
  
# 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_size  ⇒ Hash  (rw)
  
Gets the current page size.
# 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.
# 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_h  ⇒ Hash 
  
Converts the options to a hash format to be used by ::Selenium::WebDriver.
# File 'rb/lib/selenium/webdriver/common/print_options.rb', line 43
def to_h = { 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] } .compact end