Class: OoxmlParser::Fill

Inherits:
OOXMLDocumentObject show all
Defined in:
lib/ooxml_parser/xlsx_parser/workbook/style_sheet/fills/fill.rb

Overview

Parsing ‘fill` tag

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

#color2Color (readonly)

Returns second color.

Returns:

  • (Color)

    second color



10
11
12
# File 'lib/ooxml_parser/xlsx_parser/workbook/style_sheet/fills/fill.rb', line 10

def color2
  @color2
end

#fileFileReference (readonly)

Returns file of fill.

Returns:



14
15
16
# File 'lib/ooxml_parser/xlsx_parser/workbook/style_sheet/fills/fill.rb', line 14

def file
  @file
end

#idString (readonly)

Returns id of file.

Returns:

  • (String)

    id of file



12
13
14
# File 'lib/ooxml_parser/xlsx_parser/workbook/style_sheet/fills/fill.rb', line 12

def id
  @id
end

#pattern_fillPatternFill

Returns pattern fill.

Returns:



8
9
10
# File 'lib/ooxml_parser/xlsx_parser/workbook/style_sheet/fills/fill.rb', line 8

def pattern_fill
  @pattern_fill
end

#valueSymbol (readonly)

Returns value.

Returns:

  • (Symbol)

    value



16
17
18
# File 'lib/ooxml_parser/xlsx_parser/workbook/style_sheet/fills/fill.rb', line 16

def value
  @value
end

Instance Method Details

#parse(node) ⇒ Fill

Parse Fill data

Parameters:

  • node (Nokogiri::XML:Element)

    with Fill data

Returns:

  • (Fill)

    value of Fill data



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/ooxml_parser/xlsx_parser/workbook/style_sheet/fills/fill.rb', line 21

def parse(node)
  node.attributes.each do |key, value|
    case key
    when 'color2'
      @color2 = Color.new(parent: self).parse_hex_string(value.value.split.first.delete('#'))
    when 'id'
      @id = value.value.to_s
      @file = FileReference.new(parent: self).parse(node)
    when 'type'
      @type = value_to_symbol(value)
    end
  end

  node.xpath('*').each do |node_child|
    case node_child.name
    when 'patternFill'
      @pattern_fill = PatternFill.new(parent: self).parse(node_child)
    end
  end
  self
end

#to_colorOoxmlColor

Convert Fill to color

Returns:



45
46
47
# File 'lib/ooxml_parser/xlsx_parser/workbook/style_sheet/fills/fill.rb', line 45

def to_color
  pattern_fill.foreground_color
end