class RubyDocx::Elements::Drawing

Attributes

height[R]
path[RW]
width[R]
zip[RW]

Public Instance Methods

base64_data() click to toggle source
# File lib/ruby_docx/elements/drawing.rb, line 83
def base64_data
  "data:#{self.mime};base64,#{Base64.strict_encode64(self.data)}"
end
data() click to toggle source
# File lib/ruby_docx/elements/drawing.rb, line 9
def data
  if self.path
    @zip.read("word/#{@path}")
  else

  end

end
mime() click to toggle source
# File lib/ruby_docx/elements/drawing.rb, line 79
def mime
  MimeMagic.by_magic(self.data).type
end
relation_id() click to toggle source
# File lib/ruby_docx/elements/drawing.rb, line 18
def relation_id
  element = @node.xpath(".//pic:blipFill/a:blip", "a" => "http://schemas.openxmlformats.org/drawingml/2006/main", "pic" => "http://schemas.openxmlformats.org/drawingml/2006/picture").first
  if element && element.attributes.keys.index("embed")
    element.attributes["embed"].value
  else
    nil
  end
end
replace(lnk) click to toggle source
# File lib/ruby_docx/elements/drawing.rb, line 27
def replace(lnk)
  @link = lnk
end
save(path) click to toggle source
# File lib/ruby_docx/elements/drawing.rb, line 96
def save(path)
  if @zip && @path
    file = File.new(path, "wb")
    file.write(self.data)
    file.close
  end
end
style() click to toggle source
# File lib/ruby_docx/elements/drawing.rb, line 47
def style
  element = @node.xpath(".//v:shape").first

  if element && element.attributes.keys.index("style")
    element.attributes["style"].value
  else
    s = ""
    if self.width
      s += "width: #{self.width}px;"
    end

    if self.height
      s += "height: #{self.height}px;"
    end

    if self.width || self.height
      s
    else
      nil
    end
  end
end
title() click to toggle source
# File lib/ruby_docx/elements/drawing.rb, line 70
def title
  element = @node.xpath(".//v:imagedata").first
  if element && element.attributes.keys.index("title")
    element.attributes["title"].value
  else
    nil
  end
end
to_html() click to toggle source
# File lib/ruby_docx/elements/drawing.rb, line 87
def to_html
  if @link.to_s.size > 0
    "<img src='#{@link}' alt=\"#{self.title}\" style=\"#{self.style}\" />"
  else
    "<img src='#{self.base64_data}' alt=\"#{self.title}\" style=\"#{self.style}\" />"
  end

end