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

#==, #boolean_attribute_value, #initialize, #parse_xml, #with_data?

Methods included from OoxmlObjectAttributeHelper

#attribute_enabled?, #option_enabled?

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



13
14
15
# File 'lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/picture/docx_blip/file_reference.rb', line 13

def content
  @content
end

#pathString

Returns path to file.

Returns:

  • (String)

    path to file



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

def path
  @path
end

#resource_idString

Returns id of resource.

Returns:

  • (String)

    id of resource



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

def resource_id
  @resource_id
end

Instance Method Details

#parse(node) ⇒ FileReference

Parse FileReference object

Parameters:

  • node (Nokogiri::XML:Element)

    node to parse

Returns:



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# 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 = root_object.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 = root_object.unpacked_folder + root_object.root_subfolder + @path.gsub('..', '')
  if File.exist?(full_path_to_file)
    @content = if File.extname(@path) == '.xlsx'
                 parse_ole_xlsx(full_path_to_file)
               else
                 File.binread(full_path_to_file)
               end
  else
    warn "Couldn't find #{full_path_to_file} file on filesystem. Possible problem in original document"
  end
  self
end