Sha256: a966b7253f887b5d113173b143ffbba0609585d351362537a68fcde8c40de68a

Contents?: true

Size: 1.1 KB

Versions: 3

Compression:

Stored size: 1.1 KB

Contents

# frozen_string_literal: true

module OoxmlParser
  # Parsing `fonts` tag
  class Font < OOXMLDocumentObject
    attr_accessor :name, :size, :font_style, :color
    # @return [ValuedChild] vertical alignment of font
    attr_reader :vertical_alignment

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

    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
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
ooxml_parser-0.6.0 lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/style_sheet/fonts/font.rb
ooxml_parser-0.5.1 lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/style_sheet/fonts/font.rb
ooxml_parser-0.5.0 lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/style_sheet/fonts/font.rb