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

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

Constant Summary

Constants included from AttributeBuilder

AttributeBuilder::VALID_THEME_COLORS, AttributeBuilder::VALID_TYPES

Instance Attribute Summary

Attributes inherited from BaseProperty

#value

Class Method Summary collapse

Instance Method Summary collapse

Methods included from AttributeBuilder

#attributes, included

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.



20
21
22
# File 'lib/openxml/docx/properties/container_property.rb', line 20

def initialize
  @children = []
end

Class Method Details

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



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

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)


24
25
26
27
# File 'lib/openxml/docx/properties/container_property.rb', line 24

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

#each(*args, &block) ⇒ Object



29
30
31
# File 'lib/openxml/docx/properties/container_property.rb', line 29

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

#render?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/openxml/docx/properties/container_property.rb', line 33

def render?
  !children.length.zero?
end

#to_xml(xml) ⇒ Object



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

def to_xml(xml)
  return unless render?

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