summaryrefslogtreecommitdiffhomepage
path: root/lib/axlsx/workbook/worksheet/comments.rb
diff options
context:
space:
mode:
authorJurriaan Pruis <[email protected]>2014-01-15 23:44:02 +0100
committerJurriaan Pruis <[email protected]>2014-02-26 20:09:21 +0100
commitbe8e00332c73439cf17083173ea74f1505100df9 (patch)
tree383ec2e23fc0a14aa5ad90e139648a79814eeded /lib/axlsx/workbook/worksheet/comments.rb
parenta271a7d0f26ecb26d01aad00e094744d6fe8b0d2 (diff)
downloadcaxlsx-be8e00332c73439cf17083173ea74f1505100df9.tar.gz
caxlsx-be8e00332c73439cf17083173ea74f1505100df9.zip
Huge refactoring
Do not create huge strings Let Row inherit from SimpleTypedList Optimized sanitizing Optimized validation And more..
Diffstat (limited to 'lib/axlsx/workbook/worksheet/comments.rb')
-rw-r--r--lib/axlsx/workbook/worksheet/comments.rb18
1 files changed, 8 insertions, 10 deletions
diff --git a/lib/axlsx/workbook/worksheet/comments.rb b/lib/axlsx/workbook/worksheet/comments.rb
index 4023c4b8..dfc6d143 100644
--- a/lib/axlsx/workbook/worksheet/comments.rb
+++ b/lib/axlsx/workbook/worksheet/comments.rb
@@ -42,15 +42,15 @@ module Axlsx
raise ArgumentError, "Comment require an author" unless options[:author]
raise ArgumentError, "Comment requires text" unless options[:text]
raise ArgumentError, "Comment requires ref" unless options[:ref]
- @list << Comment.new(self, options)
- yield @list.last if block_given?
- @list.last
+ self << Comment.new(self, options)
+ yield last if block_given?
+ last
end
# A sorted list of the unique authors in the contained comments
# @return [Array]
def authors
- @list.map { |comment| comment.author.to_s }.uniq.sort
+ map { |comment| comment.author.to_s }.uniq.sort
end
# The relationships required by this object
@@ -65,14 +65,12 @@ module Axlsx
# @return [String]
def to_xml_string(str="")
str << '<?xml version="1.0" encoding="UTF-8"?>'
- str << '<comments xmlns="' << XML_NS << '">'
- str << '<authors>'
+ str << ('<comments xmlns="' << XML_NS << '"><authors>')
authors.each do |author|
- str << '<author>' << author.to_s << '</author>'
+ str << ('<author>' << author.to_s << '</author>')
end
- str << '</authors>'
- str << '<commentList>'
- @list.each do |comment|
+ str << '</authors><commentList>'
+ each do |comment|
comment.to_xml_string str
end
str << '</commentList></comments>'