From 93ba4b05c2e44724cfdf4c8a1352b098ea9c1482 Mon Sep 17 00:00:00 2001 From: Randy Morgan Date: Thu, 2 Aug 2012 22:38:48 +0900 Subject: bring coverage up to 100% for d_lbls and defined names release prep! --- lib/axlsx/drawing/d_lbls.rb | 18 ++++-------------- lib/axlsx/drawing/pie_3D_chart.rb | 3 ++- lib/axlsx/drawing/scatter_chart.rb | 12 +----------- lib/axlsx/workbook/defined_name.rb | 20 ++++++++++++++++---- lib/axlsx/workbook/worksheet/auto_filter.rb | 6 +++--- 5 files changed, 26 insertions(+), 33 deletions(-) (limited to 'lib') diff --git a/lib/axlsx/drawing/d_lbls.rb b/lib/axlsx/drawing/d_lbls.rb index eb4bfea5..54f054fb 100644 --- a/lib/axlsx/drawing/d_lbls.rb +++ b/lib/axlsx/drawing/d_lbls.rb @@ -2,19 +2,9 @@ module Axlsx # There are more elements in the dLbls spec that allow for # customizations and formatting. For now, I am just implementing the # basics. - # - # - # - # - # - # - # - # - # - # - # #The DLbls class manages serialization of data labels + # showLeaderLines and leaderLines are not currently implemented class DLbls # These attributes are all boolean so I'm doing a bit of a hand @@ -91,9 +81,9 @@ module Axlsx def to_xml_string(str = '') validate_attributes_for_chart_type str << '' - instance_values.each do |key, value| - next if key == :formula - str << "" + %w(d_lbl_pos show_legend_key show_val show_cat_name show_ser_name show_percent show_bubble_size show_leader_lines).each do |key| + next unless instance_values.keys.include?(key) && instance_values[key] != nil + str << "" end str << '' end diff --git a/lib/axlsx/drawing/pie_3D_chart.rb b/lib/axlsx/drawing/pie_3D_chart.rb index 059d4148..da51d08b 100644 --- a/lib/axlsx/drawing/pie_3D_chart.rb +++ b/lib/axlsx/drawing/pie_3D_chart.rb @@ -34,10 +34,11 @@ module Axlsx # @return [String] def to_xml_string(str = '') super(str) do |str_inner| + str_inner << '' str_inner << '' @series.each { |ser| ser.to_xml_string(str_inner) } - @d_lbls.to_xml_string(str) if @d_lbls + d_lbls.to_xml_string(str) if @d_lbls str_inner << '' end end diff --git a/lib/axlsx/drawing/scatter_chart.rb b/lib/axlsx/drawing/scatter_chart.rb index b3cd8c29..92ef9cf2 100644 --- a/lib/axlsx/drawing/scatter_chart.rb +++ b/lib/axlsx/drawing/scatter_chart.rb @@ -50,17 +50,7 @@ module Axlsx str_inner << '' str_inner << '' @series.each { |ser| ser.to_xml_string(str_inner) } - if @d_lbls - @d_lbls.to_xml_string(str) - end - str_inner << '' - str_inner << '' - str_inner << '' - str_inner << '' - str_inner << '' - str_inner << '' - str_inner << '' - str_inner << '' + d_lbls.to_xml_string(str) if @d_lbls str_inner << '' str_inner << '' str_inner << '' diff --git a/lib/axlsx/workbook/defined_name.rb b/lib/axlsx/workbook/defined_name.rb index da558956..ed4774e8 100644 --- a/lib/axlsx/workbook/defined_name.rb +++ b/lib/axlsx/workbook/defined_name.rb @@ -52,6 +52,7 @@ module Axlsx # creates a new DefinedName. # @param [String] formula - the formula the defined name references # @param [Hash] options - A hash of key/value pairs that will be mapped to this instances attributes. + # # @option [String] name - Specifies the name that appears in the user interface for the defined name. # This attribute is required. # The following built-in names are defined in this SpreadsheetML specification: @@ -70,9 +71,9 @@ module Axlsx # _xlnm.Extract: this defined name refers to the range containing the filtered output # values resulting from applying an advanced filter criteria to a source range. # Miscellaneous - # _xlnm .Consolidate_Area: the defined name refers to a consolidation area. - # _xlnm .Database: the range specified in the defined name is from a database data source. - # _xlnm .Sheet_Title: the defined name refers to a sheet title. + # _xlnm.Consolidate_Area: the defined name refers to a consolidation area. + # _xlnm.Database: the range specified in the defined name is from a database data source. + # _xlnm.Sheet_Title: the defined name refers to a sheet title. # @option [String] comment - A comment to optionally associate with the name # @option [String] custom_menu - The menu text for the defined name # @option [String] description - An optional description for the defined name @@ -106,7 +107,7 @@ module Axlsx @local_sheet_id = value end # string attributes that will be added when this class is evaluated - STRING_ATTRIBUTES = [:short_cut_key, :status_bar, :help, :description, :custom_menu, :comment, :name] + STRING_ATTRIBUTES = [:short_cut_key, :status_bar, :help, :description, :custom_menu, :comment] # boolean attributes that will be added when this class is evaluated BOOLEAN_ATTRIBUTES = [:workbook_parameter, :publish_to_server, :xlm, :vb_proceedure, :function, :hidden] @@ -144,8 +145,19 @@ module Axlsx end } end + + attr_reader :name + # The name of this defined name. Please refer to the class documentation for more information + def name=(value) + Axlsx::RestrictionValidator.validate 'DefinedName.name', %w(_xlnm.Print_Area _xlnm.Print_Titles _xlnm.Criteria _xlnm._FilterDatabase _xlnm.Extract _xlnm.Consolidate_Area _xlnm.Database _xlnm.Sheet_Title), value + @name = value + end + + # The formula this defined name references + attr_reader :formula def to_xml_string(str='') + raise ArgumentError, 'you must specify the name for this defined name. Please read the documentation for Axlsx::DefinedName for more details' unless name str << '" end - + end end -- cgit v1.2.3