summaryrefslogtreecommitdiffhomepage
path: root/lib/axlsx/stylesheet/color.rb
diff options
context:
space:
mode:
authorRandy Morgan <[email protected]>2011-11-20 23:22:04 +0900
committerRandy Morgan <[email protected]>2011-11-20 23:22:04 +0900
commite53f04284618713b0a90b7a691425c380e829476 (patch)
tree801fea138160f9af426d62bf94ad5bf97123ece9 /lib/axlsx/stylesheet/color.rb
downloadcaxlsx-e53f04284618713b0a90b7a691425c380e829476.tar.gz
caxlsx-e53f04284618713b0a90b7a691425c380e829476.zip
first commit
Diffstat (limited to 'lib/axlsx/stylesheet/color.rb')
-rw-r--r--lib/axlsx/stylesheet/color.rb57
1 files changed, 57 insertions, 0 deletions
diff --git a/lib/axlsx/stylesheet/color.rb b/lib/axlsx/stylesheet/color.rb
new file mode 100644
index 00000000..34567cd1
--- /dev/null
+++ b/lib/axlsx/stylesheet/color.rb
@@ -0,0 +1,57 @@
+module Axlsx
+ # The color class represents a color used for borders, fills an fonts
+ class Color
+ # Determines if the color is system color dependant
+ # @return [Boolean]
+ attr_accessor :auto
+
+ # Backwards compatability color index
+ # return [Integer]
+ #attr_accessor :indexed
+
+ # The color as defined in rgb terms.
+ # @note
+ # rgb colors need to conform to ST_UnsignedIntHex. That basically means put 'FF' before you color
+ # @example rgb colors
+ # "FF000000" is black
+ # "FFFFFFFF" is white
+ # @return [String]
+ attr_accessor :rgb
+
+ # no support for theme just yet
+ # @return [Integer]
+ #attr_accessor :theme
+
+ # The tint value.
+ # @note valid values are between -1.0 and 1.0
+ # @return [Float]
+ attr_accessor :tint
+
+ # Creates a new Color object
+ # @option options [Boolean] auto
+ # @option options [String] rgb
+ # @option options [Float] tint
+ def initialize(options={})
+ @rgb = "FF000000"
+ options.each do |o|
+ self.send("#{o[0]}=", o[1]) if self.respond_to? o[0]
+ end
+ end
+
+ def auto=(v) Axlsx::validate_boolean v; @auto = v end
+ def rgb=(v) Axlsx::validate_string v; @rgb = v end
+ def tint=(v) Axlsx::validate_float v; @tint = v end
+
+ # This version does not support themes
+ # def theme=(v) Axlsx::validate_unsigned_integer v; @theme = v end
+
+ # Indexed colors are for backward compatability which I am choosing not to support
+ # def indexed=(v) Axlsx::validate_unsigned_integer v; @indexed = v end
+
+
+ # Serializes the color
+ # @param [Nokogiri::XML::Builder] xml The document builder instance this objects xml will be added to.
+ # @return [String]
+ def to_xml(xml) xml.color(self.instance_values) end
+ end
+end