Class: OoxmlParser::ForegroundColor

Inherits:
OOXMLDocumentObject show all
Defined in:
lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/xlsx_row/xlsx_cell/cell_style/foreground_color.rb

Constant Summary

Constants inherited from OOXMLDocumentObject

OOXMLDocumentObject::DEFAULT_DIRECTORY_FOR_MEDIA

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from OOXMLDocumentObject

#==, add_to_xmls_stack, copy_file_and_rename_to_zip, copy_media_file, current_xml, dir, encrypted_file?, get_link_from_rels, media_folder, option_enabled?, unzip_file

Constructor Details

#initialize(type = nil, color = Color.new) ⇒ ForegroundColor

Returns a new instance of ForegroundColor.



6
7
8
9
# File 'lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/xlsx_row/xlsx_cell/cell_style/foreground_color.rb', line 6

def initialize(type = nil, color = Color.new)
  @type = type
  @color = color
end

Instance Attribute Details

#colorObject

Returns the value of attribute color.



4
5
6
# File 'lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/xlsx_row/xlsx_cell/cell_style/foreground_color.rb', line 4

def color
  @color
end

#typeObject

Returns the value of attribute type.



4
5
6
# File 'lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/xlsx_row/xlsx_cell/cell_style/foreground_color.rb', line 4

def type
  @type
end

Class Method Details

.parse(style_number) ⇒ Object



15
16
17
18
19
20
21
22
23
# File 'lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/xlsx_row/xlsx_cell/cell_style/foreground_color.rb', line 15

def self.parse(style_number)
  fill_color = ForegroundColor.new
  fill_style_node = XLSXWorkbook.styles_node.xpath('//xmlns:fill')[style_number.to_i].xpath('xmlns:patternFill')
  if fill_style_node && !fill_style_node.empty?
    fill_color.type = fill_style_node.attribute('patternType').value.to_sym if fill_style_node.attribute('patternType')
    fill_color.color = Color.parse_color_tag(fill_style_node.xpath('xmlns:fgColor').first) if fill_style_node.xpath('xmlns:fgColor')
  end
  fill_color
end

Instance Method Details

#nil?Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/xlsx_row/xlsx_cell/cell_style/foreground_color.rb', line 11

def nil?
  @type.nil? && @color.nil?
end