Sha256: 81953afff66e0306a34e000f33b523e94d33c0b16b5b1705714c374d415ec50e

Contents?: true

Size: 1.22 KB

Versions: 7

Compression:

Stored size: 1.22 KB

Contents

module OpenXml
  module Docx
    module Elements
      class Element
        include AttributeBuilder

        class << self
          attr_reader :property_name
          attr_reader :namespace

          def tag(*args)
            @tag = args.first if args.any?
            @tag
          end

          def name(*args)
            @property_name = args.first if args.any?
            @name
          end

          def namespace(*args)
            @namespace = args.first if args.any?
            @namespace
          end

        end

        def tag
          self.class.tag || default_tag
        end

        def name
          self.class.property_name || default_name
        end

        def namespace
          self.class.namespace || default_namespace
        end

        def to_xml(xml)
          xml[namespace].public_send(tag, xml_attributes)
        end

      private

        def default_tag
          (class_name[0, 1].downcase + class_name[1..-1]).to_sym
        end

        def default_name
          class_name.gsub(/(.)([A-Z])/, '\1_\2').downcase
        end

        def default_namespace
          :w
        end

        def class_name
          self.class.to_s.split(/::/).last
        end

      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
openxml-docx-0.10.6 lib/openxml/docx/elements/element.rb
openxml-docx-0.10.5 lib/openxml/docx/elements/element.rb
openxml-docx-0.10.4 lib/openxml/docx/elements/element.rb
openxml-docx-0.10.3 lib/openxml/docx/elements/element.rb
openxml-docx-0.10.2 lib/openxml/docx/elements/element.rb
openxml-docx-0.10.1 lib/openxml/docx/elements/element.rb
openxml-docx-0.10.0 lib/openxml/docx/elements/element.rb