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)


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

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

  @worksheet = worksheet
  @drawing = nil
end

Instance Attribute Details

#drawingDrawing (readonly)

The drawing object

Returns:



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

def drawing
  @drawing
end

#worksheetWorksheet (readonly)

The worksheet that owns the drawing

Returns:



20
21
22
# File 'lib/axlsx/workbook/worksheet/worksheet_drawing.rb', line 20

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:



30
31
32
33
# File 'lib/axlsx/workbook/worksheet/worksheet_drawing.rb', line 30

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:



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

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)


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

def has_drawing? # rubocop:disable Naming/PredicateName
  @drawing.is_a? Drawing
end

#relationshipRelationship

The relationship instance for this drawing.

Returns:



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

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: +''))


59
60
61
62
63
# File 'lib/axlsx/workbook/worksheet/worksheet_drawing.rb', line 59

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

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