Sha256: 64ccd501196284f3ea85af11b97f6d61de6ff4d6bb8e7ed50596d8ce76e844c5

Contents?: true

Size: 801 Bytes

Versions: 5

Compression:

Stored size: 801 Bytes

Contents

module Rocx
  class Style
    attr_reader :name, :type, :run, :paragraph

    def initialize(name, type, run={}, paragraph={})
      @name = name
      @type = type
      @run = run
      @paragraph = paragraph
    end

    def build_xml(xml)
      xml["w"].style("w:styleId" => name, "w:type" => type) {
        xml["w"].name("w:val" => name)
        paragraph_as_xml(xml)
        run_as_xml(xml)
      }
    end

  private

    def paragraph_as_xml(xml)
      xml["w"].pPr { xml_properties(xml, paragraph) }
    end

    def run_as_xml(xml)
      xml["w"].rPr { xml_properties(xml, run) }
    end

    def xml_properties(xml, properties)
      properties.each do |property, options|
        namespace, tag = property.split(":")
        xml[namespace].send(tag, options)
      end
    end

  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
rocx-0.7.0 lib/rocx/style.rb
rocx-0.6.0 lib/rocx/style.rb
rocx-0.5.8 lib/rocx/style.rb
rocx-0.5.7 lib/rocx/style.rb
rocx-0.5.6 lib/rocx/style.rb