class OpenXml::Docx::Properties::ContainerProperty

Attributes

children[R]

Public Class Methods

child_class(*args) click to toggle source
# 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
Also aliased as: child_classes
child_classes(*args)
Alias for: child_class
new() click to toggle source
# File lib/openxml/docx/properties/container_property.rb, line 22
def initialize
  @children = []
end

Public Instance Methods

<<(child) click to toggle source
# 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) click to toggle source
# File lib/openxml/docx/properties/container_property.rb, line 31
def each(*args, &block)
  children.each *args, &block
end
render?() click to toggle source
# File lib/openxml/docx/properties/container_property.rb, line 35
def render?
  !children.length.zero?
end
to_xml(xml) click to toggle source
# 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

Private Instance Methods

child_classes() click to toggle source
# File lib/openxml/docx/properties/container_property.rb, line 60
def child_classes
  self.class.child_classes
end
invalid_child_message() click to toggle source
# File lib/openxml/docx/properties/container_property.rb, line 51
def invalid_child_message
  class_name = self.class.to_s.split(/::/).last
  "#{class_name} must be instances of one of the following: #{child_classes}"
end
valid_child?(child) click to toggle source
# File lib/openxml/docx/properties/container_property.rb, line 56
def valid_child?(child)
  child_classes.any? {|child_class| child.is_a?(child_class) }
end