Sha256: 5c1627702aebe504763efa046db7c0cec02767168689665df813e1bf0d73b4a6

Contents?: true

Size: 1.48 KB

Versions: 10

Compression:

Stored size: 1.48 KB

Contents

module Axlsx

  # A wraper class for comments that defines its on worksheet
  # serailization
  class WorksheetComments

    # Creates a new WorksheetComments object
    # param [Worksheet] worksheet The worksheet comments in thes object belong to
    def initialize(worksheet)
      raise ArugumentError, 'You must provide a worksheet' unless worksheet.is_a?(Worksheet)
      @worksheet = worksheet
    end

    attr_reader :worksheet

    # The comments for this worksheet.
    # @return [Comments]
    def comments
      @comments ||= Comments.new(worksheet)
    end

    # Adds a comment
    # @param [Hash] options
    # @see Comments#add_comment
    def add_comment(options={})
      comments.add_comment(options)
    end 

    # The relationships defined by this objects comments collection
    # @return [Relationships]
    def relationships
      return [] unless has_comments?
      comments.relationships
    end


    # Helper method to tell us if there are comments in the comments collection
    # @return [Boolean]
    def has_comments?
      !comments.empty?
    end

    # The index in the worksheet's relationships for the VML drawing that will render the comments
    # @return [Integer]
    def index
      worksheet.relationships.index { |r| r.Type == VML_DRAWING_R } + 1
    end

    # Seraalize the object
    # @param [String] str
    # @return [String]
    def to_xml_string(str = '')
      return unless has_comments?
      str << "<legacyDrawing r:id='rId#{index}' />"
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
axlsx-1.3.6 lib/axlsx/workbook/worksheet/worksheet_comments.rb
axlsx-1.3.5 lib/axlsx/workbook/worksheet/worksheet_comments.rb
axlsx-1.3.4 lib/axlsx/workbook/worksheet/worksheet_comments.rb
axlsx-1.3.3 lib/axlsx/workbook/worksheet/worksheet_comments.rb
axlsx-1.3.2 lib/axlsx/workbook/worksheet/worksheet_comments.rb
axlsx-1.3.1 lib/axlsx/workbook/worksheet/worksheet_comments.rb
axlsx-1.2.3 lib/axlsx/workbook/worksheet/worksheet_comments.rb
axlsx-1.2.2 lib/axlsx/workbook/worksheet/worksheet_comments.rb
axlsx-1.2.1 lib/axlsx/workbook/worksheet/worksheet_comments.rb
axlsx-1.2.0 lib/axlsx/workbook/worksheet/worksheet_comments.rb