Sha256: e551d3c5587def8bb563cd86d85b4fcc66e2a677ace8d312340a8a5330f2b94b
Contents?: true
Size: 1.47 KB
Versions: 5
Compression:
Stored size: 1.47 KB
Contents
module OpenXml module Docx module Properties class ContainerProperty < BaseProperty include Enumerable include AttributeBuilder class << self def child_class(*args) if args.any? prop_name = args.first.to_s.split(/_/).map(&:capitalize).join # LazyCamelCase child_class_obj = OpenXml::Docx::Properties.const_get prop_name @child_class = OpenXml::Docx::Properties.const_get prop_name end @child_class end end def initialize @children = [] end def <<(child) raise ArgumentError, invalid_child_message unless valid_child?(child) children << child end def each(*args, &block) children.each *args, &block end def render? !children.length.zero? end def to_xml(xml) return unless render? xml["w"].public_send(tag, xml_attributes) { each { |child| child.to_xml(xml) } } end private attr_reader :children def invalid_child_message class_name = self.class.to_s.split(/::/).last "#{class_name} must be instances of OpenXml::Docx::Properties::#{child_class}" end def valid_child?(child) child.is_a?(child_class) end def child_class self.class.child_class end end end end end
Version data entries
5 entries across 5 versions & 1 rubygems