summaryrefslogtreecommitdiffhomepage
path: root/lib/axlsx/stylesheet/num_fmt.rb
diff options
context:
space:
mode:
authorRandy Morgan <[email protected]>2012-10-14 12:02:40 +0900
committerRandy Morgan <[email protected]>2012-10-14 12:02:40 +0900
commit5b5410845447772f4ba01b2ee5d03907f5897e7a (patch)
treece66d2add8423cf23b1c1a0bc35162c7447075ee /lib/axlsx/stylesheet/num_fmt.rb
parenta441bc1ff24c5b238203adb49b6e7ce208d5dabf (diff)
downloadcaxlsx-5b5410845447772f4ba01b2ee5d03907f5897e7a.tar.gz
caxlsx-5b5410845447772f4ba01b2ee5d03907f5897e7a.zip
Refactored to use options parser and serialized attributes
Diffstat (limited to 'lib/axlsx/stylesheet/num_fmt.rb')
-rw-r--r--lib/axlsx/stylesheet/num_fmt.rb35
1 files changed, 22 insertions, 13 deletions
diff --git a/lib/axlsx/stylesheet/num_fmt.rb b/lib/axlsx/stylesheet/num_fmt.rb
index d5122f7e..a796b1c7 100644
--- a/lib/axlsx/stylesheet/num_fmt.rb
+++ b/lib/axlsx/stylesheet/num_fmt.rb
@@ -3,6 +3,26 @@ module Axlsx
# A NumFmt object defines an identifier and formatting code for data in cells.
# @note The recommended way to manage styles is Styles#add_style
class NumFmt
+
+ include Axlsx::OptionsParser
+ include Axlsx::SerializedAttributes
+
+ # Creates a new NumFmt object
+ # @param [Hash] options Options for the number format object
+ # @option [Integer] numFmtId The predefined format id or new format id for this format
+ # @option [String] fomratCode The format code for this number format
+ def initialize(options={})
+ @numFmtId = 0
+ @formatCode = ""
+ parse_options options
+ end
+
+ serializable_attributes :formatCode, :numFmtId
+
+ # @return [String] The formatting to use for this number format.
+ # @see http://support.microsoft.com/kb/264372
+ attr_reader :formatCode
+
# @return [Integer] An unsinged integer referencing a standard or custom number format.
# @note
# These are the known formats I can dig up. The constant NUM_FMT_PERCENT is 9, and uses the default % formatting. Axlsx also defines a few formats for date and time that are commonly used in asia as NUM_FMT_YYYYMMDD and NUM_FRM_YYYYMMDDHHMMSS.
@@ -40,29 +60,18 @@ module Axlsx
# @see Axlsx
attr_reader :numFmtId
- # @return [String] The formatting to use for this number format.
- # @see http://support.microsoft.com/kb/264372
- attr_reader :formatCode
- def initialize(options={})
- @numFmtId = 0
- @formatCode = ""
- options.each do |o|
- self.send("#{o[0]}=", o[1]) if self.respond_to? o[0]
- end
- end
-
# @see numFmtId
def numFmtId=(v) Axlsx::validate_unsigned_int v; @numFmtId = v end
+
# @see formatCode
def formatCode=(v) Axlsx::validate_string v; @formatCode = v end
-
# Serializes the object
# @param [String] str
# @return [String]
def to_xml_string(str = '')
str << '<numFmt '
- str << instance_values.map { |key, value| '' << key.to_s << '="' << value.to_s << '"' }.join(' ')
+ serialized_attributes str
str << '/>'
end