Class: OoxmlParser::FileReference

Inherits:
OOXMLDocumentObject show all
Defined in:
lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/picture/docx_blip/file_reference.rb

Overview

Class for storing image data

Instance Attribute Summary collapse

Attributes inherited from OOXMLDocumentObject

#parent

Instance Method Summary collapse

Methods inherited from OOXMLDocumentObject

#==, add_to_xmls_stack, copy_file_and_rename_to_zip, current_xml, dir, encrypted_file?, get_link_from_rels, #initialize, unzip_file, #with_data?

Methods included from OoxmlDocumentObjectHelper

#to_hash

Constructor Details

This class inherits a constructor from OoxmlParser::OOXMLDocumentObject

Instance Attribute Details

#contentString

Returns content of file.

Returns:

  • (String)

    content of file



9
10
11
# File 'lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/picture/docx_blip/file_reference.rb', line 9

def content
  @content
end

#pathString

Returns path to file.

Returns:

  • (String)

    path to file



7
8
9
# File 'lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/picture/docx_blip/file_reference.rb', line 7

def path
  @path
end

#resource_idString

Returns id of resource.

Returns:

  • (String)

    id of resource



5
6
7
# File 'lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/picture/docx_blip/file_reference.rb', line 5

def resource_id
  @resource_id
end

Instance Method Details

#parse(node) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/picture/docx_blip/file_reference.rb', line 11

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'
  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