Sha256: eac4817724b8136ca3e57cadb17c3e6ed0f2adfeae9b9908fb75ec12e449d682

Contents?: true

Size: 1.68 KB

Versions: 2

Compression:

Stored size: 1.68 KB

Contents

module Axlsx
  # This is a utility class for serialing the drawing node in a
  # worksheet. Drawing objects have their own serialization that exports
  # a drawing document. This is only for the single node in the
  # worksheet
  class WorksheetDrawing
    # Creates a new WorksheetDrawing
    # @param [Worksheet] worksheet
    def initialize(worksheet)
      raise ArgumentError, 'you must provide a worksheet' unless worksheet.is_a?(Worksheet)

      @worksheet = worksheet
      @drawing = nil
    end

    attr_reader :worksheet

    attr_reader :drawing

    # adds a chart to the drawing object
    # @param [Class] chart_type The type of chart to add
    # @param [Hash] options Options to pass on to the drawing and chart
    # @see Worksheet#add_chart
    def add_chart(chart_type, options)
      @drawing ||= Drawing.new worksheet
      drawing.add_chart(chart_type, options)
    end

    # adds an image to the drawing object
    # @param [Hash] options Options to pass on to the drawing and image
    # @see Worksheet#add_image
    def add_image(options)
      @drawing ||= Drawing.new(worksheet)
      drawing.add_image(options)
    end

    # helper method to tell us if the drawing has something in it or not
    # @return [Boolean]
    def has_drawing?
      @drawing.is_a? Drawing
    end

    # The relationship instance for this drawing.
    # @return [Relationship]
    def relationship
      return unless has_drawing?

      Relationship.new(self, DRAWING_R, "../#{drawing.pn}")
    end

    # Serialize the drawing for the worksheet
    # @param [String] str
    def to_xml_string(str = '')
      return unless has_drawing?

      str << "<drawing r:id='#{relationship.Id}'/>"
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
caxlsx-3.4.1 lib/axlsx/workbook/worksheet/worksheet_drawing.rb
caxlsx-3.4.0 lib/axlsx/workbook/worksheet/worksheet_drawing.rb