blob: c5f5ad132537f0b542f5f225e11899ed8d3e3820 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
# frozen_string_literal: true
module Axlsx
# A wraper class for comments that defines its on worksheet
# serailization
class WorksheetComments
# Creates a new WorksheetComments object
# param [Worksheet] worksheet The worksheet comments in thes object belong to
def initialize(worksheet)
raise ArugumentError, 'You must provide a worksheet' unless worksheet.is_a?(Worksheet)
@worksheet = worksheet
end
attr_reader :worksheet
# The comments for this worksheet.
# @return [Comments]
def comments
@comments ||= Comments.new(worksheet)
end
# Adds a comment
# @param [Hash] options
# @see Comments#add_comment
def add_comment(options = {})
comments.add_comment(options)
end
# The relationships defined by this objects comments collection
# @return [Relationships]
def relationships
return [] unless has_comments?
comments.relationships
end
# Helper method to tell us if there are comments in the comments collection
# @return [Boolean]
def has_comments?
!comments.empty?
end
# The relationship id of the VML drawing that will render the comments.
# @see Relationship#Id
# @return [String]
def drawing_rId
comments.relationships.find { |r| r.Type == VML_DRAWING_R }.Id
end
# Seraalize the object
# @param [String] str
# @return [String]
def to_xml_string(str = +'')
return unless has_comments?
str << "<legacyDrawing r:id='#{drawing_rId}' />"
end
end
end
|