Class: OoxmlParser::DocumentBackground

Inherits:
Object
  • Object
show all
Defined in:
lib/ooxml_parser/docx_parser/docx_data/document_structure/document_background.rb

Overview

Class for describing Document Background w:background

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(color1 = nil, type = 'simple') ⇒ DocumentBackground

Returns a new instance of DocumentBackground.



6
7
8
9
# File 'lib/ooxml_parser/docx_parser/docx_data/document_structure/document_background.rb', line 6

def initialize(color1 = nil, type = 'simple')
  @color1 = color1
  @type = type
end

Instance Attribute Details

#color1Object

Returns the value of attribute color1.



4
5
6
# File 'lib/ooxml_parser/docx_parser/docx_data/document_structure/document_background.rb', line 4

def color1
  @color1
end

#color2Object

Returns the value of attribute color2.



4
5
6
# File 'lib/ooxml_parser/docx_parser/docx_data/document_structure/document_background.rb', line 4

def color2
  @color2
end

#imageObject

Returns the value of attribute image.



4
5
6
# File 'lib/ooxml_parser/docx_parser/docx_data/document_structure/document_background.rb', line 4

def image
  @image
end

#sizeObject

Returns the value of attribute size.



4
5
6
# File 'lib/ooxml_parser/docx_parser/docx_data/document_structure/document_background.rb', line 4

def size
  @size
end

#typeObject

Returns the value of attribute type.



4
5
6
# File 'lib/ooxml_parser/docx_parser/docx_data/document_structure/document_background.rb', line 4

def type
  @type
end

Class Method Details

.parse(node) ⇒ DocumentBackground

Parse DocumentBackground object

Parameters:

  • node (Nokogiri::XML:Element)

    node to parse

Returns:



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/ooxml_parser/docx_parser/docx_data/document_structure/document_background.rb', line 14

def self.parse(node)
  background = DocumentBackground.new
  background.color1 = Color.from_int16(node.attribute('color').value)
  node.xpath('v:background').each do |second_color|
    unless second_color.attribute('targetscreensize').nil?
      background.size = second_color.attribute('targetscreensize').value.sub(',', 'x')
    end
    second_color.xpath('v:fill').each do |fill|
      if !fill.attribute('color2').nil?
        background.color2 = Color.from_int16(fill.attribute('color2').value.split(' ').first.delete('#'))
        background.type = fill.attribute('type').value
      elsif !fill.attribute('id').nil?
        path_to_media_file = OOXMLDocumentObject.get_link_from_rels(fill.attribute('id').value)
        path_to_image = OOXMLDocumentObject.copy_media_file("#{OOXMLDocumentObject.root_subfolder}/#{path_to_media_file.gsub('..', '')}")
        background.image = path_to_image
        background.type = 'image'
      end
    end
  end
  background
end