Class: RubyDocx::Elements::OleObject
- Defined in:
- lib/ruby_docx/elements/ole_object.rb
Instance Attribute Summary collapse
-
#image_path ⇒ Object
Returns the value of attribute image_path.
-
#link ⇒ Object
Returns the value of attribute link.
-
#path ⇒ Object
Returns the value of attribute path.
-
#zip ⇒ Object
Returns the value of attribute zip.
Attributes inherited from Element
Instance Method Summary collapse
- #base64_data ⇒ Object
- #data ⇒ Object
-
#relation_id ⇒ Object
def style element = @node.xpath(“.//v:shape”).first if element && element.attributes.keys.index(“style”) element.attributes.value else nil end end.
- #replace(lnk) ⇒ Object
- #save(path) ⇒ Object
- #size ⇒ Object
- #style ⇒ Object
- #to_html ⇒ Object
- #to_latex ⇒ Object
- #to_mathml ⇒ Object
- #to_png ⇒ Object
- #to_s ⇒ Object
Methods inherited from Element
#elements, #initialize, #inspect, #to_xml
Constructor Details
This class inherits a constructor from RubyDocx::Elements::Element
Instance Attribute Details
#image_path ⇒ Object
Returns the value of attribute image_path.
27 28 29 |
# File 'lib/ruby_docx/elements/ole_object.rb', line 27 def image_path @image_path end |
#link ⇒ Object
Returns the value of attribute link.
26 27 28 |
# File 'lib/ruby_docx/elements/ole_object.rb', line 26 def link @link end |
#path ⇒ Object
Returns the value of attribute path.
26 27 28 |
# File 'lib/ruby_docx/elements/ole_object.rb', line 26 def path @path end |
#zip ⇒ Object
Returns the value of attribute zip.
26 27 28 |
# File 'lib/ruby_docx/elements/ole_object.rb', line 26 def zip @zip end |
Instance Method Details
#base64_data ⇒ Object
69 70 71 |
# File 'lib/ruby_docx/elements/ole_object.rb', line 69 def base64_data "data:image/png;base64,#{Base64.strict_encode64(self.to_png)}" end |
#data ⇒ Object
65 66 67 |
# File 'lib/ruby_docx/elements/ole_object.rb', line 65 def data self.to_png end |
#relation_id ⇒ Object
def style
element = @node.xpath(".//v:shape").first
if element && element.attributes.keys.index("style")
element.attributes["style"].value
else
nil
end
end
38 39 40 41 42 43 44 45 |
# File 'lib/ruby_docx/elements/ole_object.rb', line 38 def relation_id element = @node.xpath(".//o:OLEObject").first if element && element.attributes.keys.index("id") element.attributes["id"].value else nil end end |
#replace(lnk) ⇒ Object
97 98 99 |
# File 'lib/ruby_docx/elements/ole_object.rb', line 97 def replace(lnk) @link = lnk end |
#save(path) ⇒ Object
91 92 93 94 95 |
# File 'lib/ruby_docx/elements/ole_object.rb', line 91 def save(path) file = File.new(path, "wb") file.write(self.to_png) file.close end |
#size ⇒ Object
73 74 75 76 77 78 79 80 81 |
# File 'lib/ruby_docx/elements/ole_object.rb', line 73 def size return @size if @size sz = ImageSize.new(self.data) @size = [sz.width/7.2, sz.height/7.2] rescue nil end |
#style ⇒ Object
83 84 85 86 87 88 89 |
# File 'lib/ruby_docx/elements/ole_object.rb', line 83 def style if self.size "width: #{self.size[0]}px; height: #{self.size[1]}px;" else nil end end |
#to_html ⇒ Object
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/ruby_docx/elements/ole_object.rb', line 101 def to_html if self.style if @link "<img class=\"Wirisformula\" role='math' src='#{@link}' data-latex=\"#{self.to_latex}\" data-mathml=\"#{self.to_mathml.gsub("\n", "").gsub("<", "«").gsub(">", "»").gsub("\"", "¨")}\" style='#{self.style}' />" else "<img class=\"Wirisformula\" role='math' src='#{self.base64_data}' data-latex=\"#{self.to_latex}\" data-mathml=\"#{self.to_mathml.gsub("\n", "").gsub("<", "«").gsub(">", "»").gsub("\"", "¨")}\" style='#{self.style}' />" end else if @link "<img class=\"Wirisformula\" role='math' src='#{@link}' data-latex=\"#{self.to_latex}\" data-mathml=\"#{self.to_mathml.gsub("\n", "").gsub("<", "«").gsub(">", "»").gsub("\"", "¨")}\" style='height: 13px;' />" else "<img class=\"Wirisformula\" role='math' src='#{self.base64_data}' data-latex=\"#{self.to_latex}\" data-mathml=\"#{self.to_mathml.gsub("\n", "").gsub("<", "«").gsub(">", "»").gsub("\"", "¨")}\" style='height: 13px;' />" end end end |
#to_latex ⇒ Object
56 57 58 |
# File 'lib/ruby_docx/elements/ole_object.rb', line 56 def to_latex TeXMath.convert("#{self.to_mathml}", :from => :mathml, :to => :tex) end |
#to_mathml ⇒ Object
47 48 49 50 51 52 53 54 |
# File 'lib/ruby_docx/elements/ole_object.rb', line 47 def to_mathml io = StringIO.new(@zip.read("word/" + @path)) # xml = Mathtype::Converter.new(io) # # puts xml.to_xml # xml.to_xml mathml = MathTypeToMathML::Converter.new(io).convert end |
#to_png ⇒ Object
60 61 62 63 |
# File 'lib/ruby_docx/elements/ole_object.rb', line 60 def to_png @image_path ||= Calculus::Expression.new("#{self.to_latex}", :parse => false).to_png File.read(@image_path) end |
#to_s ⇒ Object
119 120 121 |
# File 'lib/ruby_docx/elements/ole_object.rb', line 119 def to_s self.to_latex.to_s end |