Class: Axlsx::Comments
- Inherits:
-
SimpleTypedList
- Object
- SimpleTypedList
- Axlsx::Comments
- Defined in:
- lib/axlsx/workbook/worksheet/comments.rb
Overview
Comments is a collection of Comment objects for a worksheet
Instance Attribute Summary collapse
-
#vml_drawing ⇒ VmlDrawing
readonly
the vml_drawing that holds the shapes for comments.
-
#worksheet ⇒ Worksheet
readonly
The worksheet that these comments belong to.
Instance Method Summary collapse
-
#add_comment(options = {}) {|last| ... } ⇒ Object
Adds a new comment to the worksheet that owns these comments.
-
#author_index(author) ⇒ Integer
Returns the index of the given author in the sorted authors array.
-
#authors ⇒ Array
A sorted list of the unique authors in the contained comments.
- #clear_author_caches ⇒ Object protected
-
#index ⇒ Integer
The index of this collection in the workbook.
-
#initialize(worksheet) ⇒ Comments
constructor
Creates a new Comments object.
-
#pn ⇒ String
The part name for this object.
-
#relationships ⇒ Array
The relationships required by this object.
-
#to_xml_string(str = "") ⇒ String
serialize the object.
Constructor Details
#initialize(worksheet) ⇒ Comments
Creates a new Comments object
29 30 31 32 33 34 |
# File 'lib/axlsx/workbook/worksheet/comments.rb', line 29 def initialize(worksheet) raise ArgumentError, "you must provide a worksheet" unless worksheet.is_a?(Worksheet) super(Comment) @worksheet = worksheet @vml_drawing = VmlDrawing.new(self) end |
Instance Attribute Details
#vml_drawing ⇒ VmlDrawing (readonly)
the vml_drawing that holds the shapes for comments
9 10 11 |
# File 'lib/axlsx/workbook/worksheet/comments.rb', line 9 def vml_drawing @vml_drawing end |
#worksheet ⇒ Worksheet (readonly)
The worksheet that these comments belong to
13 14 15 |
# File 'lib/axlsx/workbook/worksheet/comments.rb', line 13 def worksheet @worksheet end |
Instance Method Details
#add_comment(options = {}) {|last| ... } ⇒ Object
the author, text and ref options are required
Adds a new comment to the worksheet that owns these comments.
41 42 43 44 45 46 47 48 49 |
# File 'lib/axlsx/workbook/worksheet/comments.rb', line 41 def add_comment(={}) raise ArgumentError, "Comment require an author" unless [:author] raise ArgumentError, "Comment requires text" unless [:text] raise ArgumentError, "Comment requires ref" unless [:ref] self << Comment.new(self, ) yield last if block_given? last end |
#author_index(author) ⇒ Integer
Returns the index of the given author in the sorted authors array
60 61 62 |
# File 'lib/axlsx/workbook/worksheet/comments.rb', line 60 def () (@author_indexes ||= {})[] ||= .index() end |
#authors ⇒ Array
A sorted list of the unique authors in the contained comments
53 54 55 |
# File 'lib/axlsx/workbook/worksheet/comments.rb', line 53 def @authors ||= map { |comment| comment..to_s }.uniq.sort end |
#clear_author_caches ⇒ Object (protected)
90 91 92 93 |
# File 'lib/axlsx/workbook/worksheet/comments.rb', line 90 def @authors = nil @author_indexes = nil end |
#index ⇒ Integer
The index of this collection in the workbook. Effectively the index of the worksheet.
17 18 19 |
# File 'lib/axlsx/workbook/worksheet/comments.rb', line 17 def index @worksheet.index end |
#pn ⇒ String
The part name for this object
23 24 25 |
# File 'lib/axlsx/workbook/worksheet/comments.rb', line 23 def pn "#{COMMENT_PN % (index+1)}" end |
#relationships ⇒ Array
The relationships required by this object
66 67 68 69 |
# File 'lib/axlsx/workbook/worksheet/comments.rb', line 66 def relationships [Relationship.new(self, VML_DRAWING_R, "../#{vml_drawing.pn}"), Relationship.new(self, COMMENT_R, "../#{pn}")] end |
#to_xml_string(str = "") ⇒ String
serialize the object
74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/axlsx/workbook/worksheet/comments.rb', line 74 def to_xml_string(str="") str << '<?xml version="1.0" encoding="UTF-8"?>' str << ('<comments xmlns="' << XML_NS << '"><authors>') .each do || str << ('<author>' << .to_s << '</author>') end str << '</authors><commentList>' each do |comment| comment.to_xml_string str end str << '</commentList></comments>' end |