diff options
| author | Stefan <[email protected]> | 2022-05-13 12:21:25 +0200 |
|---|---|---|
| committer | Stefan Daschek <[email protected]> | 2022-05-18 13:04:15 +0200 |
| commit | 7a1ec08ad38c989ba7b9b30ef69d0143f71ba746 (patch) | |
| tree | 7352da876074ffd25ef8030ebe2bc2dac3bb2e3e | |
| parent | 228772ee37e75f0206a635178d991b2399870353 (diff) | |
| download | caxlsx-7a1ec08ad38c989ba7b9b30ef69d0143f71ba746.tar.gz caxlsx-7a1ec08ad38c989ba7b9b30ef69d0143f71ba746.zip | |
Implement `Title#empty?`
This is primarily a refactoring, but exposing it as a public method seems useful.
| -rw-r--r-- | lib/axlsx/drawing/title.rb | 12 |
1 files changed, 11 insertions, 1 deletions
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 << '<c:title>' - unless @text.empty? && @cell.nil? + unless empty? clean_value = Axlsx::trust_input ? @text.to_s : ::CGI.escapeHTML(Axlsx::sanitize(@text.to_s)) str << '<c:tx>' if @cell.is_a?(Cell) |
