From 7a1ec08ad38c989ba7b9b30ef69d0143f71ba746 Mon Sep 17 00:00:00 2001 From: Stefan Date: Fri, 13 May 2022 12:21:25 +0200 Subject: Implement `Title#empty?` This is primarily a refactoring, but exposing it as a public method seems useful. --- lib/axlsx/drawing/title.rb | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/axlsx/drawing/title.rb b/lib/axlsx/drawing/title.rb index d3100d43..88c2f92c 100644 --- a/lib/axlsx/drawing/title.rb +++ b/lib/axlsx/drawing/title.rb @@ -51,6 +51,16 @@ module Axlsx v end + # Check if the title is empty. + # + # A title is considered empty if it is an empty string. If the title references a cell it is *not* empty, + # even if the referenced cell is blank (because the cell’s value could still change later). + # + # @return [Boolean] + def empty? + @text.empty? && @cell.nil? + end + # Not implemented at this time. #def layout=(v) DataTypeValidator.validate 'Title.layout', Layout, v; @layout = v; end #def overlay=(v) Axlsx::validate_boolean v; @overlay=v; end @@ -61,7 +71,7 @@ module Axlsx # @return [String] def to_xml_string(str = '') str << '' - unless @text.empty? && @cell.nil? + unless empty? clean_value = Axlsx::trust_input ? @text.to_s : ::CGI.escapeHTML(Axlsx::sanitize(@text.to_s)) str << '' if @cell.is_a?(Cell) -- cgit v1.2.3