diff options
| author | Randy Morgan <[email protected]> | 2012-10-14 12:02:40 +0900 |
|---|---|---|
| committer | Randy Morgan <[email protected]> | 2012-10-14 12:02:40 +0900 |
| commit | 5b5410845447772f4ba01b2ee5d03907f5897e7a (patch) | |
| tree | ce66d2add8423cf23b1c1a0bc35162c7447075ee /lib/axlsx/stylesheet/table_style.rb | |
| parent | a441bc1ff24c5b238203adb49b6e7ce208d5dabf (diff) | |
| download | caxlsx-5b5410845447772f4ba01b2ee5d03907f5897e7a.tar.gz caxlsx-5b5410845447772f4ba01b2ee5d03907f5897e7a.zip | |
Refactored to use options parser and serialized attributes
Diffstat (limited to 'lib/axlsx/stylesheet/table_style.rb')
| -rw-r--r-- | lib/axlsx/stylesheet/table_style.rb | 33 |
1 files changed, 17 insertions, 16 deletions
diff --git a/lib/axlsx/stylesheet/table_style.rb b/lib/axlsx/stylesheet/table_style.rb index db837b99..d330beb2 100644 --- a/lib/axlsx/stylesheet/table_style.rb +++ b/lib/axlsx/stylesheet/table_style.rb @@ -4,6 +4,22 @@ module Axlsx # @note Table are not supported in this version and only the defaults required for a valid workbook are created. class TableStyle < SimpleTypedList + include Axlsx::OptionsParser + include Axlsx::SerializedAttributes + + # creates a new TableStyle object + # @raise [ArgumentError] if name option is not provided. + # @param [String] name + # @option options [Boolean] pivot + # @option options [Boolean] table + def initialize(name, options={}) + self.name = name + parse_options options + super TableStyleElement + end + + serializable_attributes :name, :pivot, :table + # The name of this table style # @return [string] attr_reader :name @@ -16,19 +32,6 @@ module Axlsx # @return [Boolean] attr_reader :table - # creates a new TableStyle object - # @raise [ArgumentError] if name option is not provided. - # @param [String] name - # @option options [Boolean] pivot - # @option options [Boolean] table - def initialize(name, options={}) - self.name = name - options.each do |o| - self.send("#{o[0]}=", o[1]) if self.respond_to? o[0] - end - super TableStyleElement - end - # @see name def name=(v) Axlsx::validate_string v; @name=v end # @see pivot @@ -40,10 +43,8 @@ module Axlsx # @param [String] str # @return [String] def to_xml_string(str = '') - attrs = instance_values.reject { |k, v| ![:name, :pivot, :table].include?(k) } - attrs[:count] = self.size str << '<tableStyle ' - str << attrs.map { |key, value| '' << key.to_s << '="' << value.to_s << '"' }.join(' ') + serialized_attributes str, {:count => self.size} str << '>' each { |table_style_el| table_style_el.to_xml_string(str) } str << '</tableStyle>' |
