Creating a nested unordered list from a unique ruby array (suggestions appreciated) -
i know shot in dark, here goes. i've been trying build unordered list using ruby similar 1 below, here catch: data receiving api not in parsable format.
i know i'm going have use recursion, i'm not sure how can convert nested (parent - children) ruby hash.
any suggestions or references resources solve issue appreciated. thank time reading question.
ruby array
[ [ "lost in translation 2003 bdrip 1080p aac x264-tomcat12\\lost in translation 2003 bdrip 1080p aac x264-tomcat12.mp4", 3450211337 ], [ " lost in translation 2003 bdrip 1080p aac x264-tomcat12\\video vc-1 bd test sample\\video vc-1 bd sample.mkv", 249150757 ], [ " lost in translation 2003 bdrip 1080p aac x264-tomcat12\\subs idx\\english.idx", 62582 ], [ " lost in translation 2003 bdrip 1080p aac x264-tomcat12\\subs idx\\french.idx", 43725 ], ] desired unordered list
<ul> <li>lost in translation 2003 bdrip 1080p aac x264-tomcat12 <ul> <li>lost in translation 2003 bdrip 1080p aac x264-tomcat12.mp4 - (3450211337)</li> </ul> <ul> <li>video vc-1 bd test sample</li> <ul> <li>video vc-1 bd sample.mkv - (249150757)</li> </ul> </ul> <ul> <li>subs idx <ul> <li>english.idx - (62582)</li> <li>french.idx - (43725)</li> </ul> </li> </ul> </li> </ul> just wanted thank guidance , help. used assistance launch tree view of torrent files on site: moviemagnet.net

the following block produce hash follows above layout. not recursive, goes depth "1" only. hope enough.
array = [ [ "lost in translation 2003 bdrip 1080p aac x264-tomcat12\\lost in translation 2003 bdrip 1080p aac x264-tomcat12.mp4", 3450211337 ], [ " lost in translation 2003 bdrip 1080p aac x264-tomcat12\\video vc-1 bd test sample\\video vc-1 bd sample.mkv", 249150757 ], [ " lost in translation 2003 bdrip 1080p aac x264-tomcat12\\subs idx\\english.idx", 62582 ], [ " lost in translation 2003 bdrip 1080p aac x264-tomcat12\\subs idx\\french.idx", 43725 ]] hash={} array.each |i| j=i.join(', ').split('\\').map(&:strip) # split @ '//' k=j[0] j.shift if hash[k].blank? hash[k]=j else l = hash[k].map{|v| v[0]} # check first element of each item in array p = l.index j[0] if p.nil? # see if current item there hash[k] << j else j.shift hash[k][p][1] = array(hash[k][p][1]) # if it's string, make array hash[k][p][1] << j.join(" ") end end end # hash {"lost in translation 2003 bdrip 1080p aac x264-tomcat12"=> [ "lost in translation 2003 bdrip 1080p aac x264-tomcat12.mp4, 3450211337", ["video vc-1 bd test sample", "video vc-1 bd sample.mkv, 249150757"], ["subs idx", ["english.idx, 62582", "french.idx, 43725"]] ] }
Comments
Post a Comment