Sha256: 18b08bde5df87c89c883cdc05b9fc7f07e64b0890e94ee5ed8158fc215f7d254

Contents?: true

Size: 1.07 KB

Versions: 2

Compression:

Stored size: 1.07 KB

Contents

module OoxmlParser
  class ParagraphMargins < TableMargins
    def initialize(top = 0.0, bottom = 0.0, left = 0.0, right = 0.0)
      @top = top
      @bottom = bottom
      @left = left
      @right = right
    end

    def round(count_of_digits = 1)
      top = @top.round(count_of_digits)
      bottom = @bottom.round(count_of_digits)
      left = @left.round(count_of_digits)
      right = @right.round(count_of_digits)
      ParagraphMargins.new(top, bottom, left, right)
    end

    def self.parse(text_body_props_node)
      margins = ParagraphMargins.new(0.127, 0.127, 0.254, 0.254)
      text_body_props_node.attributes.each do |key, value|
        case key
        when 'bIns', 'marB'
          margins.bottom = (value.value.to_f / 360_000.0).round(3)
        when 'tIns', 'marT'
          margins.top = (value.value.to_f / 360_000.0).round(3)
        when 'lIns', 'marL'
          margins.left = (value.value.to_f / 360_000.0).round(3)
        when 'rIns', 'marR'
          margins.right = (value.value.to_f / 360_000.0).round(3)
        end
      end
      margins
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ooxml_parser-0.1.2 lib/ooxml_parser/common_parser/common_data/table/margins/paragraph_margins.rb
ooxml_parser-0.1.1 lib/ooxml_parser/common_parser/common_data/table/margins/paragraph_margins.rb