Class: Axlsx::OneCellAnchor

Inherits:
Object
  • Object
show all
Defined in:
lib/axlsx/drawing/one_cell_anchor.rb

Overview

Note:

The recommended way to manage drawings, images and charts is Worksheet#add_chart or Worksheet#add_image.

This class details a single cell anchor for drawings.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(drawing, options = {}) ⇒ OneCellAnchor

Creates a new OneCellAnchor object and an Pic associated with it.

Parameters:

  • drawing (Drawing)
  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • start_at (Array)

    the col, row to start at

  • width (Integer)
  • height (Integer)
  • image_src (String)

    the file location of the image you will render

  • name (String)

    the name attribute for the rendered image

  • descr (String)

    the description of the image rendered



40
41
42
43
44
45
46
47
48
49
50
# File 'lib/axlsx/drawing/one_cell_anchor.rb', line 40

def initialize(drawing, options={})
  @drawing = drawing
  @width = 0
  @height = 0
  drawing.anchors << self      
  @from = Marker.new
  options.each do |o|
    self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
  end
  @object = Pic.new(self, options)
end

Instance Attribute Details

#drawingDrawing (readonly)

The drawing that holds this anchor

Returns:



19
20
21
# File 'lib/axlsx/drawing/one_cell_anchor.rb', line 19

def drawing
  @drawing
end

#fromMarker (readonly)

A marker that defines the from cell anchor. The default from column and row are 0 and 0 respectively

Returns:



11
12
13
# File 'lib/axlsx/drawing/one_cell_anchor.rb', line 11

def from
  @from
end

#heightInteger

the height of the graphic object in pixels this is converted to EMU at a 92 ppi resolution

Returns:

  • (Integer)


29
30
31
# File 'lib/axlsx/drawing/one_cell_anchor.rb', line 29

def height
  @height
end

#objectPic (readonly)

The object this anchor hosts

Returns:



15
16
17
# File 'lib/axlsx/drawing/one_cell_anchor.rb', line 15

def object
  @object
end

#widthInteger

the width of the graphic object in pixels. this is converted to EMU at a 92 ppi resolution

Returns:

  • (Integer)


24
25
26
# File 'lib/axlsx/drawing/one_cell_anchor.rb', line 24

def width
  @width
end

Instance Method Details

#indexInteger

The index of this anchor in the drawing

Returns:

  • (Integer)


60
61
62
# File 'lib/axlsx/drawing/one_cell_anchor.rb', line 60

def index
  @drawing.anchors.index(self)
end

#to_xml(xml) ⇒ String

Serializes the anchor

Parameters:

  • xml (Nokogiri::XML::Builder)

    The document builder instance this objects xml will be added to.

Returns:

  • (String)


67
68
69
70
71
72
73
74
75
76
# File 'lib/axlsx/drawing/one_cell_anchor.rb', line 67

def to_xml(xml)
  xml[:xdr].oneCellAnchor {
    xml.from {
      from.to_xml(xml)
    }
    xml.ext ext
    @object.to_xml(xml)
    xml.clientData
  }
end