class OoxmlParser::FileReference
Class for storing image data
Attributes
content[RW]
@return [String] content of file
path[RW]
@return [String] path to file
resource_id[RW]
@return [String] id of resource
Public Instance Methods
parse(node)
click to toggle source
Parse FileReference
object @param node [Nokogiri::XML:Element] node to parse @return [FileReference] result of parsing
# File lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/picture/docx_blip/file_reference.rb, line 18 def parse(node) node.attributes.each do |key, value| case key when 'embed', 'id', 'link' @resource_id = value.value end end return self unless @resource_id return self if @resource_id.empty? @path = OOXMLDocumentObject.get_link_from_rels(@resource_id) if !@path || @path.empty? warn "Cant find path to media file by id: #{@resource_id}" return self end return self if @path == 'NULL' return self if @path.match?(URI::DEFAULT_PARSER.make_regexp) full_path_to_file = OOXMLDocumentObject.path_to_folder + OOXMLDocumentObject.root_subfolder + @path.gsub('..', '') if File.exist?(full_path_to_file) @content = IO.binread(full_path_to_file) else warn "Couldn't find #{full_path_to_file} file on filesystem. Possible problem in original document" end self end