Class: OpenXml::Docx::Properties::ContainerProperty

Inherits:
BaseProperty
  • Object
show all
Includes:
Enumerable, HasAttributes
Defined in:
lib/openxml/docx/properties/container_property.rb

Instance Attribute Summary

Attributes inherited from BaseProperty

#value

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseProperty

#default_name, #default_namespace, #default_tag, #name, name, namespace, #namespace, tag, #tag, tag_is_one_of

Constructor Details

#initializeContainerProperty

Returns a new instance of ContainerProperty.


22
23
24
# File 'lib/openxml/docx/properties/container_property.rb', line 22

def initialize
  @children = []
end

Class Method Details

.child_class(*args) ⇒ Object Also known as: child_classes


11
12
13
14
15
16
17
18
# File 'lib/openxml/docx/properties/container_property.rb', line 11

def child_class(*args)
  @child_classes = args.map do |arg|
    prop_name = arg.to_s.split(/_/).map(&:capitalize).join # LazyCamelCase
    OpenXml::Docx::Properties.const_get prop_name
  end unless args.empty?

  @child_classes
end

Instance Method Details

#<<(child) ⇒ Object

Raises:

  • (ArgumentError)

26
27
28
29
# File 'lib/openxml/docx/properties/container_property.rb', line 26

def <<(child)
  raise ArgumentError, invalid_child_message unless valid_child?(child)
  children << child
end

#each(*args, &block) ⇒ Object


31
32
33
# File 'lib/openxml/docx/properties/container_property.rb', line 31

def each(*args, &block)
  children.each *args, &block
end

#render?Boolean

Returns:

  • (Boolean)

35
36
37
# File 'lib/openxml/docx/properties/container_property.rb', line 35

def render?
  !children.length.zero?
end

#to_xml(xml) ⇒ Object


39
40
41
42
43
44
45
# File 'lib/openxml/docx/properties/container_property.rb', line 39

def to_xml(xml)
  return unless render?

  xml["w"].public_send(tag, xml_attributes) {
    each { |child| child.to_xml(xml) }
  }
end