class OoxmlParser::ParagraphSpacing

Class for parsing Paragraph Spacing in paragraph properties ‘w:spacing`

Attributes

after[RW]

@return [OoxmlSize] value of after spacing

before[RW]

@return [OoxmlSize] value of before spacing

line[RW]

@return [OoxmlSize] value of line spacing

line_rule[RW]

@return [Symbol] value of line rule style

Public Instance Methods

parse(node) click to toggle source

Parse ParagraphSpacing @param [Nokogiri::XML:Node] node with ParagraphSpacing @return [ParagraphSpacing] result of parsing

# File lib/ooxml_parser/common_parser/common_data/paragraph/paragraph_properties/paragraph_spacing.rb, line 18
def parse(node)
  sorted_attributes(node).each do |key, value|
    case key
    when 'before'
      @before = OoxmlSize.new(value.value.to_f)
    when 'after'
      @after = OoxmlSize.new(value.value.to_f)
    when 'lineRule'
      @line_rule = value.value.sub('atLeast', 'at_least').to_sym
    when 'line'
      @line = if @line_rule == :auto
                OoxmlSize.new(value.value.to_f, :one_240th_cm)
              else
                OoxmlSize.new(value.value.to_f)
              end
    end
  end
  self
end

Private Instance Methods

sorted_attributes(node) click to toggle source

This is dirty workaround for situations Then ‘@line_rule` parsed after `@line` so getting `@line` value is totally screwed up @param [Nokogiri::XML:Node] node with ParagraphSpacing @return [Hash] hash with sorted values TODO: Totally redone parsing of spacing to remove this workaround

# File lib/ooxml_parser/common_parser/common_data/paragraph/paragraph_properties/paragraph_spacing.rb, line 46
def sorted_attributes(node)
  node.attributes.sort.reverse.to_h
end