summaryrefslogtreecommitdiffhomepage
path: root/lib/axlsx/drawing/num_data_source.rb
diff options
context:
space:
mode:
authorRandy Morgan <[email protected]>2012-05-03 09:10:23 +0900
committerRandy Morgan <[email protected]>2012-05-03 09:10:23 +0900
commite622dc54069074198990beb0462da630bad38dd0 (patch)
tree4065eb11cf4dcd68440bf8347af4509c130fb11e /lib/axlsx/drawing/num_data_source.rb
parent2dfdd1f26b1fc748da3b4edad9aeeaeae842aedb (diff)
downloadcaxlsx-e622dc54069074198990beb0462da630bad38dd0.tar.gz
caxlsx-e622dc54069074198990beb0462da630bad38dd0.zip
rebuild series data base objects with full implementation.
Address shape validation error.
Diffstat (limited to 'lib/axlsx/drawing/num_data_source.rb')
-rw-r--r--lib/axlsx/drawing/num_data_source.rb58
1 files changed, 58 insertions, 0 deletions
diff --git a/lib/axlsx/drawing/num_data_source.rb b/lib/axlsx/drawing/num_data_source.rb
new file mode 100644
index 00000000..60628883
--- /dev/null
+++ b/lib/axlsx/drawing/num_data_source.rb
@@ -0,0 +1,58 @@
+module Axlsx
+ # A numeric data source for use by charts.
+ class NumDataSource
+
+ # The tag name to use when serializing this data source.
+ # Only items defined in allowed_tag_names are allowed
+ # @return [Symbol]
+ attr_reader :tag_name
+
+ attr_reader :data
+
+ # allowed element tag names
+ # @return [Array]
+ def self.allowed_tag_names
+ [:yVal, :val]
+ end
+
+ # creates a new NumDataSource object
+ # @option options [Array] data An array of Cells or Numeric objects
+ # @option options [Symbol] tag_name see tag_name
+ def initialize(options={})
+ # override these three in child classes
+ @data_type ||= NumData
+ @tag_name ||= :val
+ @ref_tag_name ||= :numRef
+
+ @f = nil
+ @data = @data_type.new(options)
+ if options[:data] && options[:data].first.is_a?(Cell)
+ @f = Axlsx::cell_range(options[:data])
+ end
+ options.each do |o|
+ self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
+ end
+ end
+
+ # sets the tag name for this data source
+ # @param [Symbol] One of the allowed_tag_names
+ def tag_name=(v)
+ Axlsx::RestrictionValidator.validate "#{self.class.name}.tag_name", self.class.allowed_tag_names, v
+ @tag_name = v
+ end
+
+ def to_xml_string(str="")
+ str << '<c:' << tag_name.to_s << '>'
+ if @f
+ str << '<c:' << @ref_tag_name.to_s << '>'
+ str << '<c:f>' << @f.to_s << '</c:f>'
+ end
+ @data.to_xml_string str
+ if @f
+ str << '</c:' << @ref_tag_name.to_s << '>'
+ end
+ str << '</c:' << tag_name.to_s << '>'
+ end
+ end
+end
+