Class: OoxmlParser::DocumentBackground

Inherits:
OOXMLDocumentObject show all
Defined in:
lib/ooxml_parser/docx_parser/document_structure/document_background.rb

Overview

Class for describing Document Background ‘w:background`

Instance Attribute Summary collapse

Attributes inherited from OOXMLDocumentObject

#parent

Instance Method Summary collapse

Methods inherited from OOXMLDocumentObject

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

Methods included from OoxmlObjectAttributeHelper

#attribute_enabled?, #option_enabled?

Methods included from OoxmlDocumentObjectHelper

#to_hash

Constructor Details

#initialize(parent: nil) ⇒ DocumentBackground

Returns a new instance of DocumentBackground.



12
13
14
15
16
# File 'lib/ooxml_parser/docx_parser/document_structure/document_background.rb', line 12

def initialize(parent: nil)
  @color1 = nil
  @type = 'simple'
  super
end

Instance Attribute Details

#color1Object (readonly)

Returns the value of attribute color1.



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

def color1
  @color1
end

#color2Object (readonly)

Returns the value of attribute color2.



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

def color2
  @color2
end

#file_referenceFileReference (readonly)

Returns image structure.

Returns:



8
9
10
# File 'lib/ooxml_parser/docx_parser/document_structure/document_background.rb', line 8

def file_reference
  @file_reference
end

#fillFill (readonly)

Returns fill data.

Returns:

  • (Fill)

    fill data



10
11
12
# File 'lib/ooxml_parser/docx_parser/document_structure/document_background.rb', line 10

def fill
  @fill
end

#sizeObject (readonly)

Returns the value of attribute size.



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

def size
  @size
end

#typeObject (readonly)

Returns the value of attribute type.



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

def type
  @type
end

Instance Method Details

#parse(node) ⇒ DocumentBackground

Parse DocumentBackground object

Parameters:

  • node (Nokogiri::XML:Element)

    node to parse

Returns:



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/ooxml_parser/docx_parser/document_structure/document_background.rb', line 21

def parse(node)
  node.attributes.each do |key, value|
    case key
    when 'color'
      @color1 = Color.new(parent: self).parse_hex_string(value.value)
    end
  end
  node.xpath('v:background').each do |second_color|
    @size = second_color.attribute('targetscreensize').value.sub(',', 'x') unless second_color.attribute('targetscreensize').nil?
    second_color.xpath('*').each do |node_child|
      case node_child.name
      when 'fill'
        @fill = Fill.new(parent: self).parse(node_child)
      end
    end
  end
  self
end