<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>module RubyXL::OOXMLObjectClassMethods - rubyXL 3.2.6</title> <link href="../fonts.css" rel="stylesheet"> <link href="../rdoc.css" rel="stylesheet"> <script type="text/javascript"> var rdoc_rel_prefix = "../"; </script> <script src="../js/jquery.js"></script> <script src="../js/navigation.js"></script> <script src="../js/search_index.js"></script> <script src="../js/search.js"></script> <script src="../js/searcher.js"></script> <script src="../js/darkfish.js"></script> <body id="top" role="document" class="module"> <nav role="navigation"> <div id="project-navigation"> <div id="home-section" role="region" title="Quick navigation" class="nav-section"> <h2> <a href="../index.html" rel="home">Home</a> </h2> <div id="table-of-contents-navigation"> <a href="../table_of_contents.html#pages">Pages</a> <a href="../table_of_contents.html#classes">Classes</a> <a href="../table_of_contents.html#methods">Methods</a> </div> </div> <div id="search-section" role="search" class="project-section initially-hidden"> <form action="#" method="get" accept-charset="utf-8"> <div id="search-field-wrapper"> <input id="search-field" role="combobox" aria-label="Search" aria-autocomplete="list" aria-controls="search-results" type="text" name="search" placeholder="Search" spellcheck="false" title="Type to search, Up and Down to navigate, Enter to load"> </div> <ul id="search-results" aria-label="Search Results" aria-busy="false" aria-expanded="false" aria-atomic="false" class="initially-hidden"></ul> </form> </div> </div> <div id="class-metadata"> <!-- Method Quickref --> <div id="method-list-section" class="nav-section"> <h3>Methods</h3> <ul class="link-list" role="directory"> <li ><a href="#method-i-define_attribute">#define_attribute</a> <li ><a href="#method-i-define_child_node">#define_child_node</a> <li ><a href="#method-i-define_element_name">#define_element_name</a> <li ><a href="#method-i-obtain_class_variable">#obtain_class_variable</a> <li ><a href="#method-i-parse">#parse</a> </ul> </div> </div> </nav> <main role="main" aria-labelledby="module-RubyXL::OOXMLObjectClassMethods"> <h1 id="module-RubyXL::OOXMLObjectClassMethods" class="module"> module RubyXL::OOXMLObjectClassMethods </h1> <section class="description"> </section> <section id="5Buntitled-5D" class="documentation-section"> <section id="public-instance-5Buntitled-5D-method-details" class="method-section"> <header> <h3>Public Instance Methods</h3> </header> <div id="method-i-define_attribute" class="method-detail "> <div class="method-heading"> <span class="method-name">define_attribute</span><span class="method-args">(attr_name, attr_type, extra_params = {})</span> <span class="method-click-advice">click to toggle source</span> </div> <div class="method-description"> <p>Defines an attribute of OOXML object.</p> <h3 id="method-i-define_attribute-label-Parameters">Parameters<span><a href="#method-i-define_attribute-label-Parameters">¶</a> <a href="#documentation">↑</a></span></h3> <ul><li> <p><code>attribute_name</code> - Name of the element attribute as seen in the source XML. Can be either <code>"String"</code> or <code>:Symbol</code></p> <ul><li> <p>Special attibute name <code>'_'</code> (underscore) denotes the value of the element rather than attribute.</p> </li></ul> </li><li> <p><code>attribute_type</code> - Specifies the conversion type for the attribute when parsing. Available options are:</p> <ul><li> <p><code>:int</code> - <code>Integer</code></p> </li><li> <p><code>:uint</code> - Unsigned <code>Integer</code></p> </li><li> <p><code>:double</code> - <code>Float</code></u></p> </li><li> <p><code>:string</code> - <code>String</code> (no conversion)</p> </li><li> <p><code>:sqref</code> - <a href="Sqref.html">RubyXL::Sqref</a></p> </li><li> <p><code>:ref</code> - <a href="Reference.html">RubyXL::Reference</a></p> </li><li> <p><code>:bool</code> - <code>Boolean</code> (“1” and “true” convert to <code>true</code>, others to <code>false</code>)</p> </li><li> <p>one of <code>simple_types</code> - <code>String</code>, plus the list of acceptable values is saved for future validation (not used yet).</p> </li></ul> </li><li> <p><code>extra_parameters</code> - Hash of optional parameters as follows:</p> <ul><li> <p><code>:accessor</code> - Name of the accessor for this attribute to be defined on the object. If not provided, defaults to classidied <code>attribute_name</code>.</p> </li><li> <p><code>:default</code> - Value this attribute defaults to if not explicitly provided.</p> </li><li> <p><code>:required</code> - Whether this attribute is required when writing XML. If the value of the attrinute is not explicitly provided, <code>:default</code> is written instead.</p> </li><li> <p><code>:computed</code> - Do not store this attribute on <code>parse</code>, but do call the object-provided read accessor on <code>write_xml</code>.</p> </li></ul> </li></ul> <h4 id="method-i-define_attribute-label-Examples">Examples<span><a href="#method-i-define_attribute-label-Examples">¶</a> <a href="#documentation">↑</a></span></h4> <pre class="ruby"><span class="ruby-identifier">define_attribute</span>(:<span class="ruby-identifier">outline</span>, :<span class="ruby-identifier">bool</span>, :<span class="ruby-identifier">default</span> =<span class="ruby-operator">></span> <span class="ruby-keyword">true</span>) </pre> <p>A <code>Boolean</code> attribute 'outline' with default value <code>true</code> will be accessible by calling <code>obj.outline</code></p> <pre>define_attribute(:uniqueCount, :int)</pre> <p>An <code>Integer</code> attribute 'uniqueCount' accessible as <code>obj.unique_count</code></p> <pre class="ruby"><span class="ruby-identifier">define_attribute</span>(:<span class="ruby-identifier">_</span>, :<span class="ruby-identifier">string</span>, :<span class="ruby-identifier">accessor</span> =<span class="ruby-operator">></span> :<span class="ruby-identifier">expression</span>) </pre> <p>The value of the element will be accessible as a <code>String</code> by calling <code>obj.expression</code></p> <pre class="ruby"><span class="ruby-identifier">define_attribute</span>(:<span class="ruby-identifier">errorStyle</span>, <span class="ruby-node">%w{ stop warning information }</span>, :<span class="ruby-identifier">default</span> =<span class="ruby-operator">></span> <span class="ruby-string">'stop'</span>,) </pre> <p>A <code>String</code> attribute named 'errorStyle' will be accessible as <code>obj.error_style</code>, valid values are <code>"stop"</code>, <code>"warning"</code>, <code>"information"</code></p> <div class="method-source-code" id="define_attribute-source"> <pre><span class="ruby-comment"># File lib/rubyXL/objects/ooxml_object.rb, line 47</span> <span class="ruby-keyword">def</span> <span class="ruby-identifier">define_attribute</span>(<span class="ruby-identifier">attr_name</span>, <span class="ruby-identifier">attr_type</span>, <span class="ruby-identifier">extra_params</span> = {}) <span class="ruby-identifier">attrs</span> = <span class="ruby-identifier">obtain_class_variable</span>(<span class="ruby-value">:@@ooxml_attributes</span>) <span class="ruby-identifier">attr_hash</span> = <span class="ruby-identifier">extra_params</span>.<span class="ruby-identifier">merge</span>({ <span class="ruby-value">:attr_type</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">attr_type</span> }) <span class="ruby-identifier">attr_hash</span>[<span class="ruby-value">:accessor</span>] <span class="ruby-operator">||=</span> <span class="ruby-identifier">accessorize</span>(<span class="ruby-identifier">attr_name</span>) <span class="ruby-identifier">attrs</span>[<span class="ruby-identifier">attr_name</span>.<span class="ruby-identifier">to_s</span>] = <span class="ruby-identifier">attr_hash</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier">send</span>(<span class="ruby-value">:attr_accessor</span>, <span class="ruby-identifier">attr_hash</span>[<span class="ruby-value">:accessor</span>]) <span class="ruby-keyword">unless</span> <span class="ruby-identifier">attr_hash</span>[<span class="ruby-value">:computed</span>] <span class="ruby-keyword">end</span></pre> </div> </div> </div> <div id="method-i-define_child_node" class="method-detail "> <div class="method-heading"> <span class="method-name">define_child_node</span><span class="method-args">(klass, extra_params = {})</span> <span class="method-click-advice">click to toggle source</span> </div> <div class="method-description"> <p>Defines a child node of OOXML object.</p> <h3 id="method-i-define_child_node-label-Parameters">Parameters<span><a href="#method-i-define_child_node-label-Parameters">¶</a> <a href="#documentation">↑</a></span></h3> <ul><li> <p><code>klass</code> - Class (descendant of RubyXL::OOXMLObject) of the child nodes. Child node objects will be produced by calling <code>parse</code> method of that class.</p> </li><li> <p><code>extra_parameters</code> - Hash of optional parameters as follows:</p> <ul><li> <p><code>:accessor</code> - Name of the accessor for this attribute to be defined on the object. If not provided, defaults to classidied <code>attribute_name</code>.</p> </li><li> <p><code>:node_name</code> - Node name for the child node, in case it does not match the one defined by the <code>klass</code>.</p> </li><li> <p><code>:collection</code> - Whether the child node should be treated as a single node or a collection of nodes:</p> <ul><li> <p><code>false</code> (default) - child node is directly accessible through the respective accessor;</p> </li><li> <p><code>true</code> - a collection of child nodes is accessed as <code>Array</code> through the respective accessor;</p> </li><li> <p><code>:with_count</code> - same as <code>true</code>, but in addition, the attribute <code>count</code> is defined on the current object, that will be automatically set to the number of elements in the collection at the start of <code>write_xml</code> call.</p> </li></ul> </li></ul> </li></ul> <h4 id="method-i-define_child_node-label-Examples">Examples<span><a href="#method-i-define_child_node-label-Examples">¶</a> <a href="#documentation">↑</a></span></h4> <pre>define_child_node(RubyXL::Alignment)</pre> <p>Define a singular child node parsed by the RubyXL::BorderEdge.parse() and accessed by the default <code>obj.alignment</code> accessor</p> <pre class="ruby"><span class="ruby-identifier">define_child_node</span>(<span class="ruby-constant">RubyXL</span><span class="ruby-operator">::</span><span class="ruby-constant">Hyperlink</span>, :<span class="ruby-identifier">collection</span> =<span class="ruby-operator">></span> <span class="ruby-keyword">true</span>, :<span class="ruby-identifier">accessor</span> =<span class="ruby-operator">></span> :<span class="ruby-identifier">hyperlinks</span>) </pre> <p>Define an array of nodes accessed by <code>obj.hyperlinks</code> accessor, each of which will be parsed by the RubyXL::Hyperlink.parse()</p> <pre class="ruby"><span class="ruby-identifier">define_child_node</span>(<span class="ruby-constant">RubyXL</span><span class="ruby-operator">::</span><span class="ruby-constant">BorderEdge</span>, :<span class="ruby-identifier">node_name</span> =<span class="ruby-operator">></span> :<span class="ruby-identifier">left</span>) <span class="ruby-identifier">define_child_node</span>(<span class="ruby-constant">RubyXL</span><span class="ruby-operator">::</span><span class="ruby-constant">BorderEdge</span>, :<span class="ruby-identifier">node_name</span> =<span class="ruby-operator">></span> :<span class="ruby-identifier">right</span>) </pre> <p>Use class <a href="BorderEdge.html">RubyXL::BorderEdge</a> when parsing both the elements <code><left ...></code> and <code><right ...></code> elements.</p> <pre class="ruby"><span class="ruby-identifier">define_child_node</span>(<span class="ruby-constant">RubyXL</span><span class="ruby-operator">::</span><span class="ruby-constant">Font</span>, :<span class="ruby-identifier">collection</span> =<span class="ruby-operator">></span> :<span class="ruby-identifier">with_count</span>, :<span class="ruby-identifier">accessor</span> =<span class="ruby-operator">></span> :<span class="ruby-identifier">fonts</span>) </pre> <p>Upon writing of the object this was defined on, its <code>count</code> attribute will be set to the count of nodes in <code>fonts</code> array</p> <div class="method-source-code" id="define_child_node-source"> <pre><span class="ruby-comment"># File lib/rubyXL/objects/ooxml_object.rb, line 75</span> <span class="ruby-keyword">def</span> <span class="ruby-identifier">define_child_node</span>(<span class="ruby-identifier">klass</span>, <span class="ruby-identifier">extra_params</span> = {}) <span class="ruby-identifier">child_nodes</span> = <span class="ruby-identifier">obtain_class_variable</span>(<span class="ruby-value">:@@ooxml_child_nodes</span>) <span class="ruby-identifier">child_node_name</span> = (<span class="ruby-identifier">extra_params</span>[<span class="ruby-value">:node_name</span>] <span class="ruby-operator">||</span> <span class="ruby-identifier">klass</span>.<span class="ruby-identifier">class_variable_get</span>(<span class="ruby-value">:@@ooxml_tag_name</span>)).<span class="ruby-identifier">to_s</span> <span class="ruby-identifier">accessor</span> = (<span class="ruby-identifier">extra_params</span>[<span class="ruby-value">:accessor</span>] <span class="ruby-operator">||</span> <span class="ruby-identifier">accessorize</span>(<span class="ruby-identifier">child_node_name</span>)).<span class="ruby-identifier">to_sym</span> <span class="ruby-identifier">child_nodes</span>[<span class="ruby-identifier">child_node_name</span>] = { <span class="ruby-value">:class</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">klass</span>, <span class="ruby-value">:is_array</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">extra_params</span>[<span class="ruby-value">:collection</span>], <span class="ruby-value">:accessor</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">accessor</span> } <span class="ruby-identifier">define_count_attribute</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">extra_params</span>[<span class="ruby-value">:collection</span>] <span class="ruby-operator">==</span> <span class="ruby-value">:with_count</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier">send</span>(<span class="ruby-value">:attr_accessor</span>, <span class="ruby-identifier">accessor</span>) <span class="ruby-keyword">end</span></pre> </div> </div> </div> <div id="method-i-define_element_name" class="method-detail "> <div class="method-heading"> <span class="method-name">define_element_name</span><span class="method-args">(element_name)</span> <span class="method-click-advice">click to toggle source</span> </div> <div class="method-description"> <p>Defines the name of the element that represents the current OOXML object. Should only be used once per object. In case of different objects represented by the same class in different parts of OOXML tree, <code>:node_name</code> extra parameter can be used to override the default element name.</p> <h3 id="method-i-define_element_name-label-Parameters">Parameters<span><a href="#method-i-define_element_name-label-Parameters">¶</a> <a href="#documentation">↑</a></span></h3> <ul><li> <p><code>element_name</code></p> </li></ul> <h4 id="method-i-define_element_name-label-Examples">Examples<span><a href="#method-i-define_element_name-label-Examples">¶</a> <a href="#documentation">↑</a></span></h4> <pre>define_element_name 'externalReference'</pre> <div class="method-source-code" id="define_element_name-source"> <pre><span class="ruby-comment"># File lib/rubyXL/objects/ooxml_object.rb, line 103</span> <span class="ruby-keyword">def</span> <span class="ruby-identifier">define_element_name</span>(<span class="ruby-identifier">element_name</span>) <span class="ruby-keyword">self</span>.<span class="ruby-identifier">class_variable_set</span>(<span class="ruby-value">:@@ooxml_tag_name</span>, <span class="ruby-identifier">element_name</span>) <span class="ruby-keyword">end</span></pre> </div> </div> </div> <div id="method-i-obtain_class_variable" class="method-detail "> <div class="method-heading"> <span class="method-name">obtain_class_variable</span><span class="method-args">(var_name, default = {})</span> <span class="method-click-advice">click to toggle source</span> </div> <div class="method-description"> <p>Get the value of a [sub]class variable if it exists, or create the respective variable with the passed-in <code>default</code> (or +{}+, if not specified)</p> <p>Throughout this class, we are setting class variables through explicit method calls rather than by directly addressing the name of the variable because of context issues: addressing variable by name creates it in the context of defining class, while calling the setter/getter method addresses it in the context of descendant class, which is what we need.</p> <div class="method-source-code" id="obtain_class_variable-source"> <pre><span class="ruby-comment"># File lib/rubyXL/objects/ooxml_object.rb, line 14</span> <span class="ruby-keyword">def</span> <span class="ruby-identifier">obtain_class_variable</span>(<span class="ruby-identifier">var_name</span>, <span class="ruby-identifier">default</span> = {}) <span class="ruby-keyword">self</span>.<span class="ruby-identifier">class_variable_get</span>(<span class="ruby-identifier">var_name</span>) <span class="ruby-keyword">rescue</span> <span class="ruby-constant">NameError</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier">class_variable_set</span>(<span class="ruby-identifier">var_name</span>, <span class="ruby-identifier">default</span>) <span class="ruby-keyword">end</span></pre> </div> </div> </div> <div id="method-i-parse" class="method-detail "> <div class="method-heading"> <span class="method-name">parse</span><span class="method-args">(node, known_namespaces = nil)</span> <span class="method-click-advice">click to toggle source</span> </div> <div class="method-description"> <div class="method-source-code" id="parse-source"> <pre><span class="ruby-comment"># File lib/rubyXL/objects/ooxml_object.rb, line 107</span> <span class="ruby-keyword">def</span> <span class="ruby-identifier">parse</span>(<span class="ruby-identifier">node</span>, <span class="ruby-identifier">known_namespaces</span> = <span class="ruby-keyword">nil</span>) <span class="ruby-keyword">case</span> <span class="ruby-identifier">node</span> <span class="ruby-keyword">when</span> <span class="ruby-constant">String</span>, <span class="ruby-constant">IO</span>, <span class="ruby-constant">Zip</span><span class="ruby-operator">::</span><span class="ruby-constant">InputStream</span> <span class="ruby-keyword">then</span> <span class="ruby-identifier">node</span> = <span class="ruby-constant">Nokogiri</span><span class="ruby-operator">::</span><span class="ruby-constant">XML</span>.<span class="ruby-identifier">parse</span>(<span class="ruby-identifier">node</span>) <span class="ruby-keyword">end</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">node</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Nokogiri</span><span class="ruby-operator">::</span><span class="ruby-constant">XML</span><span class="ruby-operator">::</span><span class="ruby-constant">Document</span>) <span class="ruby-keyword">then</span> <span class="ruby-ivar">@namespaces</span> = <span class="ruby-identifier">node</span>.<span class="ruby-identifier">namespaces</span> <span class="ruby-identifier">node</span> = <span class="ruby-identifier">node</span>.<span class="ruby-identifier">root</span> <span class="ruby-comment"># ignorable_attr = node.attributes['Ignorable']</span> <span class="ruby-comment"># @ignorables << ignorable_attr.value if ignorable_attr</span> <span class="ruby-keyword">end</span> <span class="ruby-identifier">obj</span> = <span class="ruby-keyword">self</span>.<span class="ruby-identifier">new</span> <span class="ruby-identifier">known_attributes</span> = <span class="ruby-identifier">obtain_class_variable</span>(<span class="ruby-value">:@@ooxml_attributes</span>) <span class="ruby-identifier">content_params</span> = <span class="ruby-identifier">known_attributes</span>[<span class="ruby-string">'_'</span>] <span class="ruby-identifier">process_attribute</span>(<span class="ruby-identifier">obj</span>, <span class="ruby-identifier">node</span>.<span class="ruby-identifier">text</span>, <span class="ruby-identifier">content_params</span>) <span class="ruby-keyword">if</span> <span class="ruby-identifier">content_params</span> <span class="ruby-identifier">node</span>.<span class="ruby-identifier">attributes</span>.<span class="ruby-identifier">each_pair</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">attr_name</span>, <span class="ruby-identifier">attr</span><span class="ruby-operator">|</span> <span class="ruby-identifier">attr_name</span> = <span class="ruby-keyword">if</span> <span class="ruby-identifier">attr</span>.<span class="ruby-identifier">namespace</span> <span class="ruby-keyword">then</span> <span class="ruby-node">"#{attr.namespace.prefix}:#{attr.name}"</span> <span class="ruby-keyword">else</span> <span class="ruby-identifier">attr</span>.<span class="ruby-identifier">name</span> <span class="ruby-keyword">end</span> <span class="ruby-identifier">attr_params</span> = <span class="ruby-identifier">known_attributes</span>[<span class="ruby-identifier">attr_name</span>] <span class="ruby-keyword">next</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">attr_params</span>.<span class="ruby-identifier">nil?</span> <span class="ruby-comment"># raise "Unknown attribute [#{attr_name}] for element [#{node.name}]" if attr_params.nil?</span> <span class="ruby-identifier">process_attribute</span>(<span class="ruby-identifier">obj</span>, <span class="ruby-identifier">attr</span>.<span class="ruby-identifier">value</span>, <span class="ruby-identifier">attr_params</span>) <span class="ruby-keyword">unless</span> <span class="ruby-identifier">attr_params</span>[<span class="ruby-value">:computed</span>] } <span class="ruby-identifier">known_child_nodes</span> = <span class="ruby-identifier">obtain_class_variable</span>(<span class="ruby-value">:@@ooxml_child_nodes</span>) <span class="ruby-keyword">unless</span> <span class="ruby-identifier">known_child_nodes</span>.<span class="ruby-identifier">empty?</span> <span class="ruby-identifier">known_namespaces</span> <span class="ruby-operator">||=</span> <span class="ruby-identifier">obtain_class_variable</span>(<span class="ruby-value">:@@ooxml_namespaces</span>) <span class="ruby-identifier">node</span>.<span class="ruby-identifier">element_children</span>.<span class="ruby-identifier">each</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">child_node</span><span class="ruby-operator">|</span> <span class="ruby-identifier">ns</span> = <span class="ruby-identifier">child_node</span>.<span class="ruby-identifier">namespace</span> <span class="ruby-identifier">prefix</span> = <span class="ruby-identifier">known_namespaces</span>[<span class="ruby-identifier">ns</span>.<span class="ruby-identifier">href</span>] <span class="ruby-operator">||</span> <span class="ruby-identifier">ns</span>.<span class="ruby-identifier">prefix</span> <span class="ruby-identifier">child_node_name</span> = <span class="ruby-keyword">case</span> <span class="ruby-identifier">prefix</span> <span class="ruby-keyword">when</span> <span class="ruby-string">''</span>, <span class="ruby-keyword">nil</span> <span class="ruby-keyword">then</span> <span class="ruby-identifier">child_node</span>.<span class="ruby-identifier">name</span> <span class="ruby-keyword">else</span> <span class="ruby-node">"#{prefix}:#{child_node.name}"</span> <span class="ruby-keyword">end</span> <span class="ruby-identifier">child_node_params</span> = <span class="ruby-identifier">known_child_nodes</span>[<span class="ruby-identifier">child_node_name</span>] <span class="ruby-identifier">raise</span> <span class="ruby-node">"Unknown child node [#{child_node_name}] for element [#{node.name}]"</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">child_node_params</span>.<span class="ruby-identifier">nil?</span> <span class="ruby-identifier">parsed_object</span> = <span class="ruby-identifier">child_node_params</span>[<span class="ruby-value">:class</span>].<span class="ruby-identifier">parse</span>(<span class="ruby-identifier">child_node</span>, <span class="ruby-identifier">known_namespaces</span>) <span class="ruby-keyword">if</span> <span class="ruby-identifier">child_node_params</span>[<span class="ruby-value">:is_array</span>] <span class="ruby-keyword">then</span> <span class="ruby-identifier">index</span> = <span class="ruby-identifier">parsed_object</span>.<span class="ruby-identifier">index_in_collection</span> <span class="ruby-identifier">collection</span> = <span class="ruby-keyword">if</span> (<span class="ruby-keyword">self</span> <span class="ruby-operator"><</span> <span class="ruby-constant">RubyXL</span><span class="ruby-operator">::</span><span class="ruby-constant">OOXMLContainerObject</span>) <span class="ruby-keyword">then</span> <span class="ruby-identifier">obj</span> <span class="ruby-keyword">else</span> <span class="ruby-identifier">obj</span>.<span class="ruby-identifier">send</span>(<span class="ruby-identifier">child_node_params</span>[<span class="ruby-value">:accessor</span>]) <span class="ruby-keyword">end</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">index</span>.<span class="ruby-identifier">nil?</span> <span class="ruby-keyword">then</span> <span class="ruby-identifier">collection</span> <span class="ruby-operator"><<</span> <span class="ruby-identifier">parsed_object</span> <span class="ruby-keyword">else</span> <span class="ruby-identifier">collection</span>[<span class="ruby-identifier">index</span>] = <span class="ruby-identifier">parsed_object</span> <span class="ruby-keyword">end</span> <span class="ruby-keyword">else</span> <span class="ruby-identifier">obj</span>.<span class="ruby-identifier">send</span>(<span class="ruby-node">"#{child_node_params[:accessor]}="</span>, <span class="ruby-identifier">parsed_object</span>) <span class="ruby-keyword">end</span> } <span class="ruby-keyword">end</span> <span class="ruby-identifier">obj</span> <span class="ruby-keyword">end</span></pre> </div> </div> </div> </section> </section> </main> <footer id="validator-badges" role="contentinfo"> <p><a href="http://validator.w3.org/check/referer">Validate</a> <p>Generated by <a href="http://rdoc.rubyforge.org">RDoc</a> 4.1.2. <p>Based on <a href="http://deveiate.org/projects/Darkfish-Rdoc/">Darkfish</a> by <a href="http://deveiate.org">Michael Granger</a>. </footer>