Class: OoxmlParser::Font

Inherits:
OOXMLDocumentObject show all
Defined in:
lib/ooxml_parser/xlsx_parser/workbook/style_sheet/fonts/font.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) ⇒ Font

Returns a new instance of Font.



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

def initialize(parent: nil)
  @name = 'Calibri'
  @size = 11
  super
end

Instance Attribute Details

#colorObject

Returns the value of attribute color.



6
7
8
# File 'lib/ooxml_parser/xlsx_parser/workbook/style_sheet/fonts/font.rb', line 6

def color
  @color
end

#font_styleObject

Returns the value of attribute font_style.



6
7
8
# File 'lib/ooxml_parser/xlsx_parser/workbook/style_sheet/fonts/font.rb', line 6

def font_style
  @font_style
end

#nameObject

Returns the value of attribute name.



6
7
8
# File 'lib/ooxml_parser/xlsx_parser/workbook/style_sheet/fonts/font.rb', line 6

def name
  @name
end

#sizeObject

Returns the value of attribute size.



6
7
8
# File 'lib/ooxml_parser/xlsx_parser/workbook/style_sheet/fonts/font.rb', line 6

def size
  @size
end

#vertical_alignmentValuedChild (readonly)

Returns vertical alignment of font.

Returns:



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

def vertical_alignment
  @vertical_alignment
end

Instance Method Details

#parse(node) ⇒ Font

Parse Font object

Parameters:

  • node (Nokogiri::XML:Element)

    node to parse

Returns:

  • (Font)

    result of parsing



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

def parse(node)
  @font_style = FontStyle.new
  node.xpath('*').each do |node_child|
    case node_child.name
    when 'name'
      @name = node_child.attribute('val').value
    when 'sz'
      @size = node_child.attribute('val').value.to_f
    when 'b'
      @font_style.bold = true
    when 'i'
      @font_style.italic = true
    when 'strike'
      @font_style.strike = :single
    when 'u'
      @font_style.underlined = Underline.new(:single)
    when 'color'
      @color = OoxmlColor.new(parent: self).parse(node_child)
    when 'vertAlign'
      @vertical_alignment = ValuedChild.new(:symbol, parent: self).parse(node_child)
    end
  end
  self
end