class Parchment::DOCX::Paragraph

Public Class Methods

new(node, document) click to toggle source
Calls superclass method Parchment::Paragraph::new
# File lib/parchment/formats/docx/paragraph.rb, line 9
def initialize(node, document)
  @node = node
  @style_id = nil
  @document = document
  set_style
  super()
end

Private Instance Methods

set_style() click to toggle source

Because OfficeOpen puts all formatting on the individual elements rather than refer to a defined style, they need to be created from the element itself.

# File lib/parchment/formats/docx/paragraph.rb, line 23
def set_style
  @style = Style.new

  alignment_node = @node.xpath('.//w:jc').first
  alignment = alignment_node ? alignment_node.attributes['val'].value : nil
  @style.instance_variable_set('@text_align', alignment.to_sym) if alignment

  size_node = @node.xpath('w:pPr//w:sz').first
  font_size = size_node ? size_node.attributes['val'].value.to_i / 2 : nil
  @style.instance_variable_set('@font_size', font_size)

  bold_node = @node.xpath('w:pPr//w:b').first
  @style.instance_variable_set('@font_weight', 'bold') if bold_node

  italic_node = @node.xpath('w:pPr//w:i').first
  @style.instance_variable_set('@font_style', 'italic') if italic_node

  underline_node = @node.xpath('w:pPr//w:u').first
  @style.instance_variable_set('@text_underline_style', 'solid') if underline_node
end
set_text_runs() click to toggle source
# File lib/parchment/formats/docx/paragraph.rb, line 44
def set_text_runs
  @text_runs = @node.xpath('.//w:r').map do |child|
    Parchment::DOCX::TextRun.new(child, self, @document)
  end
end