Class: Axlsx::WorksheetDrawing

Inherits:
Object
  • Object
show all
Defined in:
lib/axlsx/workbook/worksheet/worksheet_drawing.rb

Overview

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(worksheet) ⇒ WorksheetDrawing

Creates a new WorksheetDrawing

Parameters:

Raises:

  • (ArgumentError)


9
10
11
12
13
14
# File 'lib/axlsx/workbook/worksheet/worksheet_drawing.rb', line 9

def initialize(worksheet)
  raise ArgumentError, 'you must provide a worksheet' unless worksheet.is_a?(Worksheet)

  @worksheet = worksheet
  @drawing = nil
end

Instance Attribute Details

#drawingObject (readonly)

Returns the value of attribute drawing.



18
19
20
# File 'lib/axlsx/workbook/worksheet/worksheet_drawing.rb', line 18

def drawing
  @drawing
end

#worksheetObject (readonly)

Returns the value of attribute worksheet.



16
17
18
# File 'lib/axlsx/workbook/worksheet/worksheet_drawing.rb', line 16

def worksheet
  @worksheet
end

Instance Method Details

#add_chart(chart_type, options) ⇒ Object

adds a chart to the drawing object

Parameters:

  • chart_type (Class)

    The type of chart to add

  • options (Hash)

    Options to pass on to the drawing and chart

See Also:



24
25
26
27
# File 'lib/axlsx/workbook/worksheet/worksheet_drawing.rb', line 24

def add_chart(chart_type, options)
  @drawing ||= Drawing.new worksheet
  drawing.add_chart(chart_type, options)
end

#add_image(options) ⇒ Object

adds an image to the drawing object

Parameters:

  • options (Hash)

    Options to pass on to the drawing and image

See Also:



32
33
34
35
# File 'lib/axlsx/workbook/worksheet/worksheet_drawing.rb', line 32

def add_image(options)
  @drawing ||= Drawing.new(worksheet)
  drawing.add_image(options)
end

#has_drawing?Boolean

helper method to tell us if the drawing has something in it or not

Returns:

  • (Boolean)


39
40
41
# File 'lib/axlsx/workbook/worksheet/worksheet_drawing.rb', line 39

def has_drawing?
  @drawing.is_a? Drawing
end

#relationshipRelationship

The relationship instance for this drawing.

Returns:



45
46
47
48
49
# File 'lib/axlsx/workbook/worksheet/worksheet_drawing.rb', line 45

def relationship
  return unless has_drawing?

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

#to_xml_string(str = '') ⇒ Object

Serialize the drawing for the worksheet

Parameters:

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


53
54
55
56
57
# File 'lib/axlsx/workbook/worksheet/worksheet_drawing.rb', line 53

def to_xml_string(str = '')
  return unless has_drawing?

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