Class: Axlsx::Comment

Inherits:
Object
  • Object
show all
Includes:
OptionsParser
Defined in:
lib/axlsx/workbook/worksheet/comment.rb

Overview

A comment is the text data for a comment

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from OptionsParser

#parse_options

Constructor Details

#initialize(comments, options = {}) {|_self| ... } ⇒ Comment

Creates a new comment object

Parameters:

  • comments (Comments)
  • options (Hash) (defaults to: {})
  • [String] (Hash)

    a customizable set of options

Yields:

  • (_self)

Yield Parameters:

Raises:

  • (ArgumentError)


13
14
15
16
17
18
# File 'lib/axlsx/workbook/worksheet/comment.rb', line 13

def initialize(comments, options={})
  raise ArgumentError, "A comment needs a parent comments object" unless comments.is_a?(Comments)
  @comments = comments
  parse_options options
  yield self if block_given?
end

Instance Attribute Details

#authorString

The author of this comment

Returns:

  • (String)

See Also:



27
28
29
# File 'lib/axlsx/workbook/worksheet/comment.rb', line 27

def author
  @author
end

#commentsComments (readonly)

The owning Comments object

Returns:



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

def comments
  @comments
end

#refString

The string based cell position reference (e.g. 'A1') that determines the positioning of this comment

Returns:

  • (String)


36
37
38
# File 'lib/axlsx/workbook/worksheet/comment.rb', line 36

def ref
  @ref
end

#textString

The text to render

Returns:

  • (String)


22
23
24
# File 'lib/axlsx/workbook/worksheet/comment.rb', line 22

def text
  @text
end

Instance Method Details

#author_indexInteger

The index of this author in a unique sorted list of all authors in the comment.

Returns:

  • (Integer)


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

def author_index
  @comments.authors.index(author)
end

#to_xml_string(str = "") ⇒ String

serialize the object

Parameters:

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

Returns:

  • (String)


77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/axlsx/workbook/worksheet/comment.rb', line 77

def to_xml_string(str = "")
  author = @comments.authors[author_index]
  str << '<comment ref="' << ref << '" authorId="' << author_index.to_s << '">'
  str << '<text><r>'
  str << '<rPr> <b/><color indexed="81"/></rPr>'
  str << '<t>' << author.to_s << ':
</t></r>'
  str << '<r>'
  str << '<rPr><color indexed="81"/></rPr>'
  str << '<t>' << text << '</t></r></text>'
  str << '</comment>'
end

#vml_shapeVmlShape

The vml shape that will render this comment

Returns:



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

def vml_shape
  @vml_shape ||= initialize_vml_shape
end