Note that there are some explanatory texts on larger screens.

plurals
  1. PORecursion, mixed arrays, Ruby
    primarykey
    data
    text
    <p>I have a recursive problem that is not returning as I expect and I'm not sure how to change the function.</p> <p>I would like an array containing both strings and arrays that derive from a chunk of text that is separated by boundaries defined in the text. The first pass works, but the second pass doesn't seem to correctly turn strings containing the boundary keyword into arrays and have them replace themselves in the parent array.</p> <p>Recursion functions:</p> <pre><code>def separate(text,boundary = nil) # returns array of strings and arrays containing all of the parts of the email textList = [] if !boundary #look in the email for "boundary= X" text.scan(/(?&lt;=boundary=).*/) do |bound| textList = recursiveSplit(text,bound) end end if boundary textList = recursiveSplit(text,boundary) end puts textList.count puts '\n' puts textList.inspect return textList end def recursiveSplit(chunk,boundary) if chunk.is_a? String searchString = "--" + boundary ar = chunk.split(searchString) return ar elsif chunk.is_a? Array chunk do |bit| recursiveSplit(bit,boundary); end end end </code></pre> <p>Example of text variable:</p> <pre><code>MIME-Version: 1.0 Received: by 10.112.170.40 with HTTP; Fri, 3 May 2013 05:08:21 -0700 (PDT) Date: Fri, 3 May 2013 08:08:21 -0400 Delivered-To: me@gmail.com Message-ID: &lt;CADPp44E47syuXvP1K-aemhcU7vdSijZkfKLu-74QPWs9U9551Q@mail.gmail.com&gt; Subject: MiB 5/3/13 7:43AM (EST) From: Me &lt;me@gmail.com&gt; To: Someone &lt;someone@aol.com&gt; Content-Type: multipart/mixed; boundary=BNDRY1 --BNDRY1 Content-Type: multipart/alternative; boundary=BNDRY2 --BNDRY2 Content-Type: text/plain; charset=ISO-8859-1 -TEXT STUFF HERE. SAYING THINGS ABOUT CERTAIN THINGS --BNDRY2 Content-Type: text/html; charset=ISO-8859-1 HTML FORMATTED TEXT STUFF --BNDRY2-- --BNDRY1 Content-Type: application/zip; name="Make it Brief.ipa.zip" Content-Disposition: attachment; filename="Make it Brief.ipa.zip" Content-Transfer-Encoding: base64 X-Attachment-Id: f_hg9biuno0 &lt;&lt;FILE DATA&gt;&gt; --BNDRY1-- </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload