diff options
| author | Randy Morgan <[email protected]> | 2012-10-14 12:25:09 +0900 |
|---|---|---|
| committer | Randy Morgan <[email protected]> | 2012-10-14 12:25:09 +0900 |
| commit | 93b70a39999ac4d06e43e495f3fd283e9630d9d2 (patch) | |
| tree | bb2846edfc328ff9143c548c2a25eab23b8c9179 /lib/axlsx/workbook/worksheet/page_setup.rb | |
| parent | 5b5410845447772f4ba01b2ee5d03907f5897e7a (diff) | |
| download | caxlsx-93b70a39999ac4d06e43e495f3fd283e9630d9d2.tar.gz caxlsx-93b70a39999ac4d06e43e495f3fd283e9630d9d2.zip | |
Refactored to use options parser and serialized attributes.
Diffstat (limited to 'lib/axlsx/workbook/worksheet/page_setup.rb')
| -rw-r--r-- | lib/axlsx/workbook/worksheet/page_setup.rb | 39 |
1 files changed, 20 insertions, 19 deletions
diff --git a/lib/axlsx/workbook/worksheet/page_setup.rb b/lib/axlsx/workbook/worksheet/page_setup.rb index b3e1051e..ec76cd61 100644 --- a/lib/axlsx/workbook/worksheet/page_setup.rb +++ b/lib/axlsx/workbook/worksheet/page_setup.rb @@ -6,8 +6,24 @@ module Axlsx # @see Worksheet#initialize class PageSetup + include Axlsx::OptionsParser + include Axlsx::SerializedAttributes + + # Creates a new PageSetup object + # @option options [Integer] fit_to_height Number of vertical pages to fit on + # @option options [Integer] fit_to_width Number of horizontal pages to fit on + # @option options [Symbol] orientation Orientation of the page (:default, :landscape, :portrait) + # @option options [String] paper_height Height of paper (number followed by unit identifier: "297mm", "11in") + # @option options [String] paper_width Width of paper (number followed by unit identifier: "210mm", "8.5in") + # @option options [Integer] scale Print scaling (percent value, integer ranging from 10 to 400) + # @option options [Integer] paper_size - the size of paper to use + def initialize(options = {}) + parse_options options + end + + serializable_attributes :fit_to_height, :fit_to_width, :orientation, :paper_height, :paper_width, :scale, :paper_size + # TODO: Attributes defined by Open XML spec that are not implemented yet: - # # * blackAndWhite # * cellComments # * copies @@ -16,7 +32,6 @@ module Axlsx # * firstPageNumber # * horizontalDpi # * pageOrder - # * paperSize # * useFirstPageNumber # * usePrinterDefaults # * verticalDpi @@ -176,24 +191,10 @@ module Axlsx @paper_size = size end - # Creates a new PageSetup object - # @option options [Integer] fit_to_height Number of vertical pages to fit on - # @option options [Integer] fit_to_width Number of horizontal pages to fit on - # @option options [Symbol] orientation Orientation of the page (:default, :landscape, :portrait) - # @option options [String] paper_height Height of paper (number followed by unit identifier: "297mm", "11in") - # @option options [String] paper_width Width of paper (number followed by unit identifier: "210mm", "8.5in") - # @option options [Integer] scale Print scaling (percent value, integer ranging from 10 to 400) - # @option options [Integer] paper_size - the size of paper to use - def initialize(options = {}) - set(options) - end - - # Set some or all page settings at once. + # Set some or all page settings at once. # @param [Hash] options The page settings to set (possible keys are :fit_to_height, :fit_to_width, :orientation, :paper_height, :paper_width, and :scale). def set(options) - options.each do |k, v| - send("#{k}=", v) if respond_to? "#{k}=" - end + parse_options options end # @see fit_to_height @@ -234,7 +235,7 @@ module Axlsx # @return [String] def to_xml_string(str = '') str << '<pageSetup ' - str << instance_values.reject{ |k, v| k == 'worksheet' }.map{ |k,v| k.gsub(/_(.)/){ $1.upcase } << %{="#{v}"} }.join(' ') + serialized_attributes str str << '/>' end end |
