summaryrefslogtreecommitdiffhomepage
path: root/lib/axlsx/workbook/worksheet/print_options.rb
blob: 6e1b2bfd1db237778ebd1f8dc4210a305b0ebe78 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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
# frozen_string_literal: true

module Axlsx
  # Options for printing a worksheet. All options are boolean and false by default.
  #
  # @note The recommended way to manage print options is via Worksheet#print_options
  # @see Worksheet#print_options
  # @see Worksheet#initialize
  class PrintOptions
    include Axlsx::OptionsParser
    include Axlsx::SerializedAttributes
    include Axlsx::Accessors
    # Creates a new PrintOptions object
    # @option options [Boolean] grid_lines Whether grid lines should be printed
    # @option options [Boolean] headings Whether row and column headings should be printed
    # @option options [Boolean] horizontal_centered Whether the content should be centered horizontally
    # @option options [Boolean] vertical_centered  Whether the content should be centered vertically
    def initialize(options = {})
      @grid_lines = @headings = @horizontal_centered = @vertical_centered = false
      set(options)
    end

    serializable_attributes :grid_lines, :headings, :horizontal_centered, :vertical_centered
    boolean_attr_accessor :grid_lines, :headings, :horizontal_centered, :vertical_centered

    # Set some or all options at once.
    # @param [Hash] options The options to set (possible keys are :grid_lines, :headings, :horizontal_centered, and :vertical_centered).
    def set(options)
      parse_options options
    end

    # Serializes the page options element.
    # @note As all attributes default to "false" according to the xml schema definition, the generated xml includes only those attributes that are set to true.
    # @param [String] str
    # @return [String]
    def to_xml_string(str = +'')
      serialized_tag 'printOptions', str
    end
  end
end