Class: Axlsx::WorksheetComments

Inherits:
Object
  • Object
show all
Defined in:
lib/axlsx/workbook/worksheet/worksheet_comments.rb

Overview

A wraper class for comments that defines its on worksheet serailization

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(worksheet) ⇒ WorksheetComments

Creates a new WorksheetComments object param [Worksheet] worksheet The worksheet comments in thes object belong to

Raises:

  • (ArugumentError)


9
10
11
12
# File 'lib/axlsx/workbook/worksheet/worksheet_comments.rb', line 9

def initialize(worksheet)
  raise ArugumentError, 'You must provide a worksheet' unless worksheet.is_a?(Worksheet)
  @worksheet = worksheet
end

Instance Attribute Details

#worksheetObject (readonly)

Returns the value of attribute worksheet.



14
15
16
# File 'lib/axlsx/workbook/worksheet/worksheet_comments.rb', line 14

def worksheet
  @worksheet
end

Instance Method Details

#add_comment(options = {}) ⇒ Object

Adds a comment

Parameters:

  • options (Hash) (defaults to: {})

See Also:



25
26
27
# File 'lib/axlsx/workbook/worksheet/worksheet_comments.rb', line 25

def add_comment(options={})
  comments.add_comment(options)
end

#commentsComments

The comments for this worksheet.

Returns:



18
19
20
# File 'lib/axlsx/workbook/worksheet/worksheet_comments.rb', line 18

def comments
  @comments ||= Comments.new(worksheet)
end

#has_comments?Boolean

Helper method to tell us if there are comments in the comments collection

Returns:

  • (Boolean)


39
40
41
# File 'lib/axlsx/workbook/worksheet/worksheet_comments.rb', line 39

def has_comments?
  !comments.empty?
end

#indexInteger

The index in the worksheet's relationships for the VML drawing that will render the comments

Returns:

  • (Integer)


45
46
47
# File 'lib/axlsx/workbook/worksheet/worksheet_comments.rb', line 45

def index
  worksheet.relationships.index { |r| r.Type == VML_DRAWING_R } + 1
end

#relationshipsRelationships

The relationships defined by this objects comments collection

Returns:



31
32
33
34
# File 'lib/axlsx/workbook/worksheet/worksheet_comments.rb', line 31

def relationships
  return [] unless has_comments?
  comments.relationships
end

#to_xml_string(str = '') ⇒ String

Seraalize the object

Parameters:

  • str (String) (defaults to: '')

Returns:

  • (String)


52
53
54
55
# File 'lib/axlsx/workbook/worksheet/worksheet_comments.rb', line 52

def to_xml_string(str = '')
  return unless has_comments?
  str << "<legacyDrawing r:id='rId#{index}' />"
end