Class: RubyDocx::Convertor::Html::Header

Inherits:
Base
  • Object
show all
Defined in:
lib/ruby_docx/convertors/elements/html/header.rb

Instance Attribute Summary

Attributes inherited from Base

#css, #tag

Instance Method Summary collapse

Methods inherited from Base

#build, #initialize, #styles

Constructor Details

This class inherits a constructor from RubyDocx::Convertor::Html::Base

Instance Method Details

#convertObject



2
3
4
5
6
7
8
9
10
11
12
13
14
# File 'lib/ruby_docx/convertors/elements/html/header.rb', line 2

def convert
  default_styles = {
      'font-weight' => 'bold',
      'font-size' => (20 - tag.name.gsub(/\D/, '').to_i)
  }
  node = RubyDocx::Paragraph.new(nil, default_styles)
  tag.children.each do |child|
    if child.is_a?(Nokogiri::XML::Text) && child.content.present?
      node.append(RubyDocx::Row.new(child.content, default_styles))
    end
  end
  node
end