Class: Axlsx::Comment

Inherits:
Object
  • Object
show all
Includes:
Accessors, 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)

    The comment collection this comment belongs to

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

    a customizable set of options

  • [Boolean] (Hash)

    a customizable set of options

Yields:

  • (_self)

Yield Parameters:

Raises:

  • (ArgumentError)


16
17
18
19
20
21
22
# File 'lib/axlsx/workbook/worksheet/comment.rb', line 16

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

Instance Attribute Details

#commentsComments (readonly)

Returns:



29
30
31
# File 'lib/axlsx/workbook/worksheet/comment.rb', line 29

def comments
  @comments
end

#refString|Cell

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

Returns:



34
35
36
# File 'lib/axlsx/workbook/worksheet/comment.rb', line 34

def ref
  @ref
end

Instance Method Details

#author_indexInteger

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

Returns:

  • (Integer)


50
51
52
# File 'lib/axlsx/workbook/worksheet/comment.rb', line 50

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

#to_xml_string(str = "") ⇒ String

serialize the object

Parameters:

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

Returns:

  • (String)


64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/axlsx/workbook/worksheet/comment.rb', line 64

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

#vml_shapeVmlShape

The vml shape that will render this comment

Returns:



43
44
45
# File 'lib/axlsx/workbook/worksheet/comment.rb', line 43

def vml_shape
  @vml_shape ||= initialize_vml_shape
end