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
# 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

#drawingObject (readonly)

Returns the value of attribute drawing.



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

def drawing
  @drawing
end

#worksheetObject (readonly)

Returns the value of attribute worksheet.



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

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:



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

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:



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

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)


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

def has_drawing?
  @drawing.is_a? Drawing
end

#indexInteger

returns the index of the worksheet releationship that defines this drawing.

Returns:

  • (Integer)


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

def index
   worksheet.relationships.index{ |r| r.Type == DRAWING_R } +1 
end

#relationshipRelationship

The relationship required by this object

Returns:



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

def relationship
  return unless has_drawing?
  Relationship.new(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
# File 'lib/axlsx/workbook/worksheet/worksheet_drawing.rb', line 59

def to_xml_string(str = '')
  return unless has_drawing? 
  str << "<drawing r:id='rId#{index}'/>"
end