Class: Writexlsx::Package::Comments

Inherits:
Object
  • Object
show all
Includes:
Utility
Defined in:
lib/write_xlsx/package/comments.rb

Constant Summary

Constants included from Utility

Utility::COL_MAX, Utility::ROW_MAX, Utility::SHEETNAME_MAX, Utility::STR_MAX

Instance Method Summary collapse

Methods included from Utility

#absolute_char, #check_dimensions, #check_dimensions_and_update_max_min_values, #check_parameter, #convert_date_time, delete_files, #ptrue?, #put_deprecate_message, #row_col_notation, #store_col_max_min_values, #store_row_max_min_values, #substitute_cellref, #underline_attributes, #xl_cell_to_rowcol, #xl_col_to_name, #xl_range, #xl_range_formula, #xl_rowcol_to_cell, #xml_str

Constructor Details

#initialize(worksheet) ⇒ Comments

Returns a new instance of Comments.



126
127
128
129
130
131
# File 'lib/write_xlsx/package/comments.rb', line 126

def initialize(worksheet)
  @worksheet = worksheet
  @writer = Package::XMLWriterSimple.new
  @author_ids = {}
  @comments = {}
end

Instance Method Details

#[](row) ⇒ Object



133
134
135
# File 'lib/write_xlsx/package/comments.rb', line 133

def [](row)
  @comments[row]
end

#add(comment) ⇒ Object



137
138
139
140
141
142
143
144
# File 'lib/write_xlsx/package/comments.rb', line 137

def add(comment)
  if @comments[comment.row]
    @comments[comment.row][comment.col] = comment
  else
    @comments[comment.row] = {}
    @comments[comment.row][comment.col] = comment
  end
end

#assemble_xml_fileObject



158
159
160
161
162
163
164
165
166
167
# File 'lib/write_xlsx/package/comments.rb', line 158

def assemble_xml_file
  write_xml_declaration
  write_comments
  write_authors(sorted_comments)
  write_comment_list(sorted_comments)

  @writer.end_tag('comments')
  @writer.crlf
  @writer.close
end

#empty?Boolean

Returns:

  • (Boolean)


146
147
148
# File 'lib/write_xlsx/package/comments.rb', line 146

def empty?
  @comments.empty?
end

#has_comment_in_row?(row) ⇒ Boolean

Returns:

  • (Boolean)


187
188
189
# File 'lib/write_xlsx/package/comments.rb', line 187

def has_comment_in_row?(row)
  !!@comments[row]
end

#set_xml_writer(filename) ⇒ Object



154
155
156
# File 'lib/write_xlsx/package/comments.rb', line 154

def set_xml_writer(filename)
  @writer.set_xml_writer(filename)
end

#sizeObject



150
151
152
# File 'lib/write_xlsx/package/comments.rb', line 150

def size
  sorted_comments.size
end

#sorted_commentsObject



169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
# File 'lib/write_xlsx/package/comments.rb', line 169

def sorted_comments
  @sorted_comments if @sorted_comments

  @sorted_comments = []
  # We sort the comments by row and column but that isn't strictly required.
  @comments.keys.sort.each do |row|
    @comments[row].keys.sort.each do |col|
      # Set comment visibility if required and not already user defined.
      @comments[row][col].visible ||= 1 if comments_visible?

      # Set comment author if not already user defined.
      @comments[row][col].author ||= @worksheet.comments_author
      @sorted_comments << @comments[row][col]
    end
  end
  @sorted_comments
end