Class: OoxmlParser::Font

Inherits:
OOXMLDocumentObject show all
Defined in:
lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/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

#==, add_to_xmls_stack, copy_file_and_rename_to_zip, current_xml, dir, encrypted_file?, get_link_from_rels, unzip_file, #with_data?

Methods included from OoxmlDocumentObjectHelper

#to_hash

Constructor Details

#initialize(parent: nil) ⇒ Font

Returns a new instance of Font.



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

def initialize(parent: nil)
  @name = 'Calibri'
  @size = 11
  @parent = parent
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/style_sheet/fonts/font.rb', line 4

def color
  @color
end

#font_styleObject

Returns the value of attribute font_style.



4
5
6
# File 'lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/style_sheet/fonts/font.rb', line 4

def font_style
  @font_style
end

#nameObject

Returns the value of attribute name.



4
5
6
# File 'lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/style_sheet/fonts/font.rb', line 4

def name
  @name
end

#sizeObject

Returns the value of attribute size.



4
5
6
# File 'lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/style_sheet/fonts/font.rb', line 4

def size
  @size
end

#vertical_alignmentValuedChild (readonly)

Returns vertical alignment of font.

Returns:



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

def vertical_alignment
  @vertical_alignment
end

Instance Method Details

#parse(node) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/style_sheet/fonts/font.rb', line 14

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