summaryrefslogtreecommitdiffhomepage
path: root/lib/axlsx/workbook/worksheet/table_style_info.rb
blob: 82320b5694e3e671f20846fb66d8e6f279873f7c (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
41
42
43
44
45
46
47
48
49
50
51
module Axlsx

  # The table style info class manages style attributes for defined tables in
  # a worksheet
  class TableStyleInfo

    # creates a new TableStyleInfo instance
    # @param [Hash] options
    # @option [Boolean] show_first_column indicates if the first column should
    #                   be shown
    # @option [Boolean] show_last_column indicates if the last column should
    #                   be shown
    # @option [Boolean] show_column_stripes indicates if column stripes should
    #                   be shown
    # @option [Boolean] show_row_stripes indicates if row stripes should be shown
    # @option [String] name The name of the style to apply to your table. 
    #                  Only predefined styles are currently supported.
    #                  @see Annex G. (normative) Predefined SpreadsheetML Style Definitions in part 1 of the specification.
    def initialize(options = {})
      initialize_defaults
      @name = 'TableStyleMedium9'
      options.each do |k, v|
        send("#{k}=", v) if respond_to? "#{k}="
      end
    end

    # boolean attributes for this object
    boolean_attr_accessor :show_first_column, :show_last_column, :show_row_stripes, :show_column_stripes

    # Initialize all the values to false as Excel requires them to
    # explicitly be disabled or all will show.
    def initialize_defaults
      %w(show_first_column show_last_column show_row_stripes show_column_stripes).each do |attr|
        self.send("#{attr}=", 0)
      end
    end

    # The name of the table style.
    attr_accessor :name

    # seralizes this object to an xml string
    # @param [String] str the string to contact this objects serialization to.
    def to_xml_string(str = '')
      str << '<tableStyleInfo '
      instance_values.each do |key, value|
        str << Axlsx::camel(key, false) << "='#{value}' "
      end
      str << '/>'
    end
  end
end