Class: OoxmlParser::Fonts

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

Overview

Parsing ‘fonts` tag

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) ⇒ Fonts

Returns a new instance of Fonts.



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

def initialize(parent: nil)
  @fonts_array = []
  super
end

Instance Attribute Details

#fonts_arrayArray, Font

Returns array of number formats.

Returns:

  • (Array, Font)

    array of number formats



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

def fonts_array
  @fonts_array
end

Instance Method Details

#[](key) ⇒ Array<Font>

Returns accessor.

Returns:

  • (Array<Font>)

    accessor



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

def [](key)
  @fonts_array[key]
end

#parse(node) ⇒ Fonts

Parse Fonts data

Parameters:

  • node (Nokogiri::XML:Element)

    with NumberFormats data

Returns:

  • (Fonts)

    value of NumberFormats data



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/ooxml_parser/xlsx_parser/workbook/style_sheet/fonts.rb', line 23

def parse(node)
  node.attributes.each do |key, value|
    case key
    when 'count'
      @count = value.value.to_i
    end
  end

  node.xpath('*').each do |node_child|
    case node_child.name
    when 'font'
      @fonts_array << Font.new(parent: self).parse(node_child)
    end
  end
  self
end