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, #dash_types, delete_files, #fill_properties, #float_to_str, #layout_properties, #line_fill_properties, #line_properties, #palette_color, #pixels_to_points, #process_workbook_options, #ptrue?, #put_deprecate_message, #quote_sheetname, #r_id_attributes, #row_col_notation, #shape_style_base, #store_col_max_min_values, #store_row_max_min_values, #substitute_cellref, #underline_attributes, #v_shape_attributes_base, #v_shape_style_base, #value_or_raise, #write_anchor, #write_auto_fill, #write_comment_path, #write_div, #write_fill, #write_font, #write_stroke, #write_xml_declaration, #xl_cell_to_rowcol, #xl_col_to_name, #xl_range, #xl_range_formula, #xl_rowcol_to_cell, #xml_str

Constructor Details

#initialize(worksheet) ⇒ Comments


239
240
241
242
243
244
# File 'lib/write_xlsx/package/comments.rb', line 239

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

Instance Method Details

#[](row) ⇒ Object


246
247
248
# File 'lib/write_xlsx/package/comments.rb', line 246

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

#add(comment) ⇒ Object


250
251
252
253
254
255
256
257
# File 'lib/write_xlsx/package/comments.rb', line 250

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


271
272
273
274
275
276
277
278
# File 'lib/write_xlsx/package/comments.rb', line 271

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

#empty?Boolean


259
260
261
# File 'lib/write_xlsx/package/comments.rb', line 259

def empty?
  @comments.empty?
end

#has_comment_in_row?(row) ⇒ Boolean


299
300
301
# File 'lib/write_xlsx/package/comments.rb', line 299

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

#set_xml_writer(filename) ⇒ Object


267
268
269
# File 'lib/write_xlsx/package/comments.rb', line 267

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

#sizeObject


263
264
265
# File 'lib/write_xlsx/package/comments.rb', line 263

def size
  sorted_comments.size
end

#sorted_commentsObject


280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
# File 'lib/write_xlsx/package/comments.rb', line 280

def sorted_comments
  unless @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
  end

  @sorted_comments
end