Class: OpenXml::Properties::ContainerProperty

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

Direct Known Subclasses

TransparentContainerProperty

Instance Attribute Summary

Attributes inherited from BaseProperty

#value

Class Method Summary collapse

Instance Method Summary collapse

Methods included from HasAttributes

#attributes, included, #required_attributes

Methods inherited from BaseProperty

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

Constructor Details

#initializeContainerProperty

Returns a new instance of ContainerProperty.



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

def initialize
  @children = []
end

Class Method Details

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



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

def child_class(*args)
  unless args.empty?
    @child_classes = args.map { |arg|
      prop_name = arg.to_s.split(/_/).map(&:capitalize).join # LazyCamelCase
      const_name = (self.to_s.split(/::/)[0...-1] + [prop_name]).join("::")
      Object.const_get const_name
    }
  end

  @child_classes
end

Instance Method Details

#<<(child) ⇒ Object

Raises:

  • (ArgumentError)


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

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

#each(*args, &block) ⇒ Object



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

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

#render?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/openxml/properties/container_property.rb', line 39

def render?
  !children.length.zero?
end

#to_xml(xml) ⇒ Object



43
44
45
46
47
48
49
# File 'lib/openxml/properties/container_property.rb', line 43

def to_xml(xml)
  return unless render?

  apply_namespace(xml).public_send(tag, xml_attributes) {
    each { |child| child.to_xml(xml) }
  }
end