Class: Axlsx::WorksheetDrawing
- Inherits:
-
Object
- Object
- Axlsx::WorksheetDrawing
- 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
-
#drawing ⇒ Drawing
readonly
The drawing object.
-
#worksheet ⇒ Worksheet
readonly
The worksheet that owns the drawing.
Instance Method Summary collapse
-
#add_chart(chart_type, options) ⇒ Object
adds a chart to the drawing object.
-
#add_image(options) ⇒ Object
adds an image to the drawing object.
-
#has_drawing? ⇒ Boolean
helper method to tell us if the drawing has something in it or not.
-
#initialize(worksheet) ⇒ WorksheetDrawing
constructor
Creates a new WorksheetDrawing.
-
#relationship ⇒ Relationship
The relationship instance for this drawing.
-
#to_xml_string(str = +'')) ⇒ Object
Serialize the drawing for the worksheet.
Constructor Details
#initialize(worksheet) ⇒ WorksheetDrawing
Creates a new WorksheetDrawing
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
#drawing ⇒ Drawing (readonly)
The drawing object
24 25 26 |
# File 'lib/axlsx/workbook/worksheet/worksheet_drawing.rb', line 24 def drawing @drawing end |
#worksheet ⇒ Worksheet (readonly)
The worksheet that owns the drawing
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
30 31 32 33 |
# File 'lib/axlsx/workbook/worksheet/worksheet_drawing.rb', line 30 def add_chart(chart_type, ) @drawing ||= Drawing.new worksheet drawing.add_chart(chart_type, ) end |
#add_image(options) ⇒ Object
adds an image to the drawing object
38 39 40 41 |
# File 'lib/axlsx/workbook/worksheet/worksheet_drawing.rb', line 38 def add_image() @drawing ||= Drawing.new(worksheet) drawing.add_image() end |
#has_drawing? ⇒ Boolean
helper method to tell us if the drawing has something in it or not
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 |
#relationship ⇒ Relationship
The relationship instance for this drawing.
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
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 |