module RubyXL::OOXMLObjectClassMethods
def define_child_node(klass, extra_params = {})
define_child_node(RubyXL::Font, :collection => :with_count, :accessor => :fonts)
Use class RubyXL::BorderEdge when parsing both the elements
define_child_node(RubyXL::BorderEdge, :node_name => :right)
define_child_node(RubyXL::BorderEdge, :node_name => :left)
Define an array of nodes accessed by obj.hyperlinks accessor, each of which will be parsed by the RubyXL::Hyperlink.parse()
define_child_node(RubyXL::Hyperlink, :collection => true, :accessor => :hyperlinks)
Define a singular child node parsed by the RubyXL::BorderEdge.parse() and accessed by the default obj.alignment accessor
define_child_node(RubyXL::Alignment)
==== Examples
* +:with_count+ - same as +true+, but in addition, the attribute +count+ is defined on the current object, that will be automatically set to the number of elements in the collection at the start of +write_xml+ call.
* +true+ - a collection of child nodes is accessed as +Array+ through the respective accessor;
* +false+ (default) - child node is directly accessible through the respective accessor;
* +:collection+ - Whether the child node should be treated as a single node or a collection of nodes:
* +:node_name+ - Node name for the child node, in case it does not match the one defined by the +klass+.
* +:accessor+ - Name of the accessor for this attribute to be defined on the object. If not provided, defaults to classidied +attribute_name+.
* +extra_parameters+ - Hash of optional parameters as follows:
* +klass+ - Class (descendant of RubyXL::OOXMLObject) of the child nodes. Child node objects will be produced by calling +parse+ method of that class.
=== Parameters
Defines a child node of OOXML object.
def define_child_node(klass, extra_params = {}) child_nodes = obtain_class_variable(:@@ooxml_child_nodes) child_node_name = (extra_params[:node_name] || klass.class_variable_get(:@@ooxml_tag_name)).to_s accessor = (extra_params[:accessor] || accessorize(child_node_name)).to_sym child_nodes[child_node_name] = { :class => klass, :is_array => extra_params[:collection], :accessor => accessor } define_count_attribute if extra_params[:collection] == :with_count self.send(:attr_accessor, accessor) end