d: ao & elsewhere, use of map & select
authorRalph Amissah <ralph@amissah.com>
Thu, 19 Mar 2015 22:38:21 +0000 (18:38 -0400)
committerRalph Amissah <ralph@amissah.com>
Tue, 24 Mar 2015 01:46:12 +0000 (21:46 -0400)
16 files changed:
data/doc/sisu/CHANGELOG_v6
lib/sisu/develop/ao_character_check.rb
lib/sisu/develop/ao_composite.rb
lib/sisu/develop/ao_doc_str.rb
lib/sisu/develop/ao_endnotes.rb
lib/sisu/develop/ao_hash_digest.rb
lib/sisu/develop/ao_idx.rb
lib/sisu/develop/ao_images.rb
lib/sisu/develop/ao_misc_arrange.rb
lib/sisu/develop/ao_numbering.rb
lib/sisu/develop/cgi_sql_common.rb
lib/sisu/develop/db_sqltxt.rb
lib/sisu/develop/html_harvest_topics.rb
lib/sisu/develop/html_tune.rb
lib/sisu/develop/hub_loop_markup_files.rb
lib/sisu/develop/hub_options.rb

index d0745d6b1032fe3448c5656c8f55ee27adb52197..e51e0883aeaef51421579b59ab84c47f90c2180b 100644 (file)
@@ -126,6 +126,8 @@ http://www.jus.uio.no/sisu/pkg/src/sisu_6.4.0.orig.tar.xz
 
   * manifest, html ids added to label/identify content
 
+  * ao and elsewhere, use of map and select
+
 ** SiSU "UnFrozen" - prior to end of Debian Freeze
   (upstream bugfix 6.3.2 (5.7.2) intended for Jessie (packaged for Debian as
   5.7.1-2) was not accepted)
index b7cfc6df4cc3fe3d06b419109b170ad10f346e45..2596c739d3b1fdaa02e3e6da5b1e5602c5b8094d 100644 (file)
@@ -63,9 +63,9 @@ module SiSU_AO_CharacterCheck
     end
     def character_check_and_oldstyle_endnote_array
       data=@data
-      @tuned_file,@endnote_array=[],[]
+      @endnote_array=[]
       endnote_no=1
-      data.each do |dob|
+      @tuned_file=data.select do |dob|
         unless dob.is ==:table
           dob.obj=dob.obj.strip.
             gsub(/^[{~}]\s*$/,'').
@@ -93,9 +93,8 @@ module SiSU_AO_CharacterCheck
             end
           end
         end
-        @tuned_file << dob if dob.is_a?(Object)
-      end
-      @tuned_file=@tuned_file.flatten.compact
+        dob if dob.is_a?(Object)
+      end.flatten.compact
       [@tuned_file,@endnote_array]
     end
   end
index a60593d97a23e2d8e6c138adde3bcb8286d66f77..8a59f0641ec68ef3d76306a714cb3b1d524880a2 100644 (file)
@@ -127,7 +127,6 @@ module SiSU_Assemble
       end
     end
     def loadfile(loadfilename)
-      tuned_file=[]
       begin
         if FileTest.file?(loadfilename)
           insert_array=IO.readlines(loadfilename,'')
@@ -141,18 +140,17 @@ module SiSU_Assemble
                 loadfilename,
               ).txt_grey
             end
-            if loadfilename =~/\S+?\.ss[im]$/
-              insert_array.each do |para|
-                tuned_file << insert?(para)
+            tuned_file=if loadfilename =~/\S+?\.ss[im]$/
+              insert_array.each.map do |para|
+                insert?(para)
               end
             elsif loadfilename =~/\S+?\.sst$/
-              insert_array.each do |para|
-                tuned_file << para
+              insert_array.each.map do |para|
+                para
               end
-            end
+            end.flatten.compact
           end
         end
-        tuned_file=tuned_file.flatten.compact
       rescue
         SiSU_Errors::Rescued.new($!,$@,@opt.selections.str,@opt.fns).location do
           __LINE__.to_s + ':' + __FILE__
index 7f054660d3801fbbbcdd59788f61a116b0e46154..c5f39ed407c81da9a28a4fa26e1a2615624b1211 100644 (file)
@@ -1138,8 +1138,8 @@ module SiSU_AO_DocumentStructureExtract
       SiSU_AO_DocumentStructure::ObjectPara.new.paragraph(h)
     end
     def build_lines(type=:none)
-      lines,lines_new=@data,[]
-      lines.each do |line|
+      lines=@data
+      lines.each.map do |line|
         line=if line =~/\S/ \
         and line !~/^(?:code(?:\.[a-z][0-9a-z_]+)?\{|\}code)/ \
         and line !~/^(?:```[ ]+code(?:\.[a-z][0-9a-z_]+)?|```(?:\s+[~-][#]|\s+\~\{.+?\}\~)?\s*$)/ \
@@ -1156,9 +1156,8 @@ module SiSU_AO_DocumentStructureExtract
           line.gsub(/\s*$/,"#{Mx[:br_nl]}")
         else line
         end
-        lines_new << line
+        line
       end
-      lines_new
     end
   end
   class Structure                                          # this must happen early
index c6dafd4cc60ffa2689472f1505d8702b29488d3d..c523345205bd40e14b86e2b8749da3e463e39e54 100644 (file)
@@ -66,9 +66,8 @@ module SiSU_AO_Endnotes
     end
     def endnotes
       data=@data
-      @tuned_file=[]
       endnote_ref=1
-      data.each do |dob|
+      @tuned_file=data.each.map do |dob|
                                                                                # manually numbered endnotes <!e(\d)!> <!e_(\d)!> -->
         if @md.opt.selections.str =~/--no-asterisk|--no-annotate/
           dob.obj=dob.obj.
@@ -89,20 +88,20 @@ module SiSU_AO_Endnotes
             word_mode=endnote_call_number(word_mode)
             dob.obj=word_mode.join(' ')
             endnote_ref+=1
-          when /~\^(?:\s|$)|<:e>/                                              #%note inserts endnotes previously gathered from /^(<!e[:_]!>|[-~]\{{3})/ (in earlier loop)
+          when /~\^(?:\s|$)/                                              #%note inserts endnotes previously gathered from /^(<!e[:_]!>|[-~]\{{3})/ (in earlier loop)
             word_mode=dob.obj.scan(/\S+/m)
             word_mode=endnote_call_number(word_mode)
             dob.obj=word_mode.join(' ')
             endnote_ref+=1
           end
         end
-        @tuned_file << dob
-      end
+        dob
+      end.flatten
       @endnote_counter,
         @endnote_counter_asterisk,
         @endnote_counter_dag=
         1,1,1
-      @tuned_file=@tuned_file.flatten
+      @tuned_file
     end
     def endnote_call_number(words)
       words.each do |word|
@@ -123,9 +122,9 @@ module SiSU_AO_Endnotes
               "#{Mx[:en_b_o]}\*#{@endnote_counter_asterisk} ")
             @endnote_counter_asterisk+=1
           end
-        when /~\^|<:e>/
+        when /~\^/
           if @endnote_array
-            word.gsub!(/~\^|<:e>/,
+            word.gsub!(/~\^/,
               "#{@endnote_array[@endnote_counter-1]}")
             @endnote_counter+=1
           end
index 97087a2a4c3e2eb89ce1194c7b7603b3a81f7408..39f34f85f2e3f79c3d12fa59ad4e4e829863e02f 100644 (file)
@@ -103,9 +103,8 @@ module SiSU_AO_Hash
       #use md5 or to create hash of each ao object including ocn, & add into to each ao object
     end
     def endnote_digest(data)
-      t_o_bit=[]
-      data.each do |en_plus|
-        t_o_bit <<= case en_plus
+      data.each.map do |en_plus|
+        case en_plus
         when /#{Mx[:en_a_o]}|#{Mx[:en_b_o]}/
           if en_plus =~/#{Mx[:en_a_o]}.+?#{Mx[:en_a_c]}|#{Mx[:en_b_o]}.+?#{Mx[:en_b_c]}/
             t_o_txt,en_open,en_txt,en_close=
@@ -133,8 +132,7 @@ module SiSU_AO_Hash
           end
         else en_plus
         end
-      end
-      t_o_bit.join
+      end.join
     end
     def stamped(t_o,hash_class) #decide what hash information is most useful, is compromise necessary?
       t_o.obj=SiSU_TextRepresentation::Alter.new(t_o).strip_clean_of_extra_spaces
index 80dca60155ae0804837522858cf397eb6886b225..cbe3f00c59cbf4af7af0a990060dbfeb1ed86394 100644 (file)
@@ -413,12 +413,9 @@ module SiSU_AO_BookIndex
       tuned_file
     end
     def clean_index(data)                                  #check on use of dob
-      tuned_file=[]
-      data.each do |para|
-        para=para.gsub(/\n*#{@rgx_idx}/m,'')
-        tuned_file << para
+      data.each.map do |para|
+        para.gsub(/\n*#{@rgx_idx}/m,'')
       end
-      tuned_file
     end
   end
 end
index 2e152573de14eb4610155b6cefed55bcf8450101..e0f20d33113a0fc58c93fb4688ce4bb308d2b248 100644 (file)
@@ -67,7 +67,6 @@ module SiSU_AO_Images
     end
     def images
       data=@data
-      tuned_file=[]
       @rmgk=false
       imagemagick_=true      #imagemagick_=SiSU_Env::InfoSettings.new.program?('rmagick')
       if imagemagick_
@@ -85,7 +84,7 @@ module SiSU_AO_Images
           ).warn
         end
       end
-      data.each do |dob|
+      data.select do |dob|
         unless dob.is ==:table
           dob.obj=dob.obj.strip
           if dob.obj =~/#{Mx[:lnk_o]}\s*\S+\.(?:png|jpg|gif)(?:\s*|\s+.+)?#{Mx[:lnk_c]}(?:#{Mx[:url_o]}\S+?#{Mx[:url_c]}|image)/
@@ -179,9 +178,8 @@ module SiSU_AO_Images
             dob.obj=dob.obj.gsub(/(#{Mx[:lnk_o]})\s*(\S+\.(?:png|jpg|gif))\s+/i,'\1\2 ')
           end
         end
-        tuned_file << dob unless dob.nil?
+        dob unless dob.nil?
       end
-      tuned_file
     end
   end
 end
index d474f553747676a67611f17b4183efedb69b0e4f..8f8fe3684fded9a99088e3ce87d07ac464e1aa14 100644 (file)
@@ -189,7 +189,6 @@ module SiSU_AO_MiscArrangeText
     end
     def prepare_text
       data=@data
-      data_new=[],[]
       if data[0] =~ /^#!\s*(?:\/usr\/bin\/env sisu|\/usr\/bin\/sisu)/ # remove bang from top #! (however file is stripped, so will be removed provided no content precedes it)
         data[0]=data[0].gsub(/^#!\s*\/usr\/bin\/sisu/,'').
           gsub(/^#!\s*\/usr\/bin\/env sisu/,'')
@@ -198,11 +197,10 @@ module SiSU_AO_MiscArrangeText
         data[0]=data[0].gsub(/^(SiSU\s*[\d.]*)$/,'% \1').
           gsub(/^(sisu-[\d.]+)$/,'% \1')
       end
-      data.each do |para|
+      data.each.map do |para|
         para=conditional_headings(para)
-        data_new << markup_blocks(para)
-      end
-      data_new=data_new.flatten
+        markup_blocks(para)
+      end.flatten
     end
   end
 end
index 6e9f28530c74d9d90d583bef54a56cac70e86958..38054fa1db0c4cc0fe67180cc2233937d2eb7b10 100644 (file)
@@ -172,7 +172,6 @@ module SiSU_AO_Numbering
         gsub(/#{Mx[:gl_bullet]}/,'')
     end
     def auto_number_heading_ie_title(data)                                             #also does some segment naming
-      @tuned_file=[]
       if defined? @md.make.num_top \
       and @md.make.num_top \
       and @md.make.num_top !~/^$/
@@ -185,7 +184,7 @@ module SiSU_AO_Numbering
       end
       chapter_number_counter=0
       data=data.compact
-      data.each do |dob| #@md.seg_names << [additions to segment names]
+      @tuned_file=data.each.map do |dob| #@md.seg_names << [additions to segment names]
         title_no=nil
         if dob.is ==:heading \
         && dob.autonum_ \
@@ -274,9 +273,8 @@ module SiSU_AO_Numbering
           dob.tags=set_tags(dob.tags,dob.name)
         end
         dob.tags=dob.tags.uniq if defined? dob.tags
-        @tuned_file << dob
-      end
-      @tuned_file=@tuned_file.flatten
+        dob
+      end.flatten
     end
     def ocn(data)                                                                      #and auto segment numbering increment
       @tuned_file=SiSU_AO_DocumentStructureExtract::OCN.new(@md,data,@fnx,@process).ocn
@@ -287,10 +285,9 @@ module SiSU_AO_Numbering
       @tuned_file
     end
     def minor_numbering(data)                                                          #and auto segment numbering increment
-      @tuned_file=[]
       number_small,letter_small=0,0
       letter=%w( a b c d e f g h i j k l m n o p q r s t u v w x y z )
-      data.each do |dob|
+      @tuned_file=data.each.map do |dob|
         if dob.of ==:heading \
         || dob.of ==:heading_insert \
         || dob.of ==:para \
@@ -313,9 +310,8 @@ module SiSU_AO_Numbering
             end
           end
         end
-        @tuned_file << dob
-      end
-      @tuned_file=@tuned_file.flatten
+        dob
+      end.flatten
     end
     def leading_zeros_fixed_width_number(possible_seg_name)
       if possible_seg_name.to_s =~/^([0-9]+?\.|[0-9]+)$/m       #!~/[.,:-]+/
index 3974caf03607cbb6b9b3f0917c178f8eabbbc343..33e9c1509877d0146eb56b818d984802f96b25a0 100644 (file)
@@ -908,13 +908,11 @@ module SiSU_CGI_SQL
                     else nil
                     end
                     @search_regx=if unescaped_search                                     #check
-                      search_regex=[]
-                      build=unescaped_search.scan(/\S+/).each do |g|
+                      search_regex=unescaped_search.scan(/\S+/).each.map do |g|
                          (g.to_s =~/(AND|OR)/) \
-                         ? (search_regex << '|')
-                         : (search_regex << %{#{g.to_s}})
-                      end
-                      search_regex=search_regex.join(' ')
+                         ? ('|')
+                         : (%{#{g.to_s}})
+                      end.join(' ')
                       search_regex=search_regex.gsub(/\s*\|\s*/,'|')
                       Regexp.new(search_regex, Regexp::IGNORECASE)
                     else nil
index 869845967170ae7a2e7bc34c63576994b40cc26b..1e3efbc781fe46c1629ffddea2ddee58b6ee934f 100644 (file)
@@ -66,9 +66,9 @@ module SiSU_DbText
         gsub(/#{Mx[:lnk_o]}\s*(.+?)\s*#{Mx[:lnk_c]}#{Mx[:url_o]}\S+?#{Mx[:url_c]}/m,'\1')
     end
     def clean_searchable_text_from_document_objects(arr)
-      txt_arr,en=[],[]
+      en=[]
       arr=(arr.is_a?(String)) ? [ arr ] : arr
-      arr.each do |s|
+      txt_arr=arr.each.map do |s|
         s=s.gsub(/#{Mx[:fa_o]}[a-z]{1,4}#{Mx[:fa_o_c]}/m,'').
             gsub(/#{Mx[:fa_c_o]}[a-z]{1,4}#{Mx[:fa_c]}/m,'').
             gsub(/<br>/m,' ')
@@ -77,27 +77,26 @@ module SiSU_DbText
           gsub(/#{Mx[:en_b_o]}.+?#{Mx[:en_b_c]}/m,'').
           gsub(/ \s+/m,' ')
         #p s if s =~/[^ \nA-Za-z0-9'"`?!#@$%^&*=+,.;:\[\]()<>{}‹›|\\\/~_-]/
-        txt_arr << s
+        s
       end
       txt_arr=txt_arr << en
       txt=txt_arr.flatten.join("\n")
       special_character_escape(txt)
     end
     def clean_document_objects_body(arr)
-      txt_arr,en,en_arr=[],[],[]
+      en=[]
       arr=(arr.is_a?(String)) ? [ arr ] : arr
-      arr.each do |s|
+      txt_arr=arr.each.map do |s|
         en << s.scan(/#{Mx[:en_a_o]}\s*(.+?)\s*#{Mx[:en_a_c]}/m)
         s=s.
           gsub(/#{Mx[:en_a_o]}\s*(\d+).+?#{Mx[:en_a_c]}/m,
             '<sup>\1</sup>').
           gsub(/#{Mx[:en_b_o]}.+?#{Mx[:en_b_c]}/m,'').
           gsub(/ \s+/m,' ')
-        txt_arr << s
+        s
       end
-      en.flatten.each do |e|
-        e=e.sub(/^(\d+)\s*/,'<sup>\1</sup> ')
-        en_arr << e
+      en_arr=en.flatten.each.map do |e|
+        e.sub(/^(\d+)\s*/,'<sup>\1</sup> ')
       end
       txt_arr=txt_arr << en_arr
       txt=txt_arr.flatten.join("\n<br>")
index bd461377d640de697a1217cd607e211019628f99..22c880d60e47a1461398c7a80f21373fc4bda5a9 100644 (file)
@@ -158,10 +158,9 @@ module SiSU_HarvestTopics
         end
         idx_array[lang] <<=if @idx_list =~/;/
           g=@idx_list.scan(/[^;]+/)
-          idxl=[]
-          g.each do |i|
+          g.each.map do |i|
             i=i.strip
-            idxl << {
+            {
               filename: filename,
               file: file,
               rough_idx: i,
@@ -171,7 +170,6 @@ module SiSU_HarvestTopics
               lang: lang
             }
           end
-          idxl
         else {
             filename: filename,
             file: file,
index 89757bb9c1ae03fb1b2be8e086dadc33e8474d19..70c7e0ee52fdd35d04b475342839fa379e3b0248 100644 (file)
@@ -151,7 +151,6 @@ module SiSU_HTML_Tune
     end
     def songsheet_array(data)
       data_tuned=[]
-      #@tuned_file=[]
       data.each do |dob|
         dob=amp_angle_brackets(dob)
         dob=endnotes_html(dob)
@@ -162,9 +161,8 @@ module SiSU_HTML_Tune
       data_tuned
     end
     def urls(data)
-      @words=[]
-      data.each do |word|
-        @words << if word=~/#{Mx[:lnk_o]}(.+?)#{Mx[:lnk_c]}(?:#{Mx[:url_o]}\S+?#{Mx[:url_c]}|#{Mx[:rel_o]}\S+?#{Mx[:rel_c]}|image)/
+      @words=data.each.map do |word|
+        if word=~/#{Mx[:lnk_o]}(.+?)#{Mx[:lnk_c]}(?:#{Mx[:url_o]}\S+?#{Mx[:url_c]}|#{Mx[:rel_o]}\S+?#{Mx[:rel_c]}|image)/
           http_=true
           if word =~/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}#{Mx[:url_o]}\S+?#{Mx[:url_c]}/
             m,u=/#{Mx[:lnk_o]}(.+?)#{Mx[:lnk_c]}#{Mx[:url_o]}(\S+?)#{Mx[:url_c]}/.match(word).captures
@@ -208,9 +206,7 @@ module SiSU_HTML_Tune
           word
         else word
         end
-        word
-      end
-      @words=@words.join(' ')
+      end.join(' ')
     end
     def url_markup(dob)
       unless dob.is==:code
@@ -293,10 +289,9 @@ module SiSU_HTML_Tune
     end
     def output
       data=@data
-      @tuned_file=[]
-      data.each do |dob|
+      @tuned_file=data.each.map do |dob|
         dob.obj=dob.obj.strip.chomp
-        @tuned_file << dob
+        dob
       end
       @tuned_file << "\n<EOF>" if (@md.fns =~/\.sst0/) #remove
       @tuned_file
index 541b205af3c6943e905199b39e7c451a94d51172..6b27b8d35ae926a08d9e81297420174dba6b0093 100644 (file)
@@ -136,6 +136,9 @@ module SiSU_Hub_Loops
           files_translated_idx << x[1]
         end
       end
+      #files_translated_idx=number_of_files.select do |x|
+      #  x[1] if x[1].length > 1
+      #end
       if files_translated_idx.flatten.length > 1
         SiSU_Screen::Ansi.new(
           @opt.act[:color_state][:set],
index 6e22c2ae4e9e7b88a20e9cbf1a67d6e53508a46f..f6a40be9fb9aa5dd38e4f37c690421c226082759 100644 (file)
@@ -249,17 +249,15 @@ module SiSU_Commandline
       end
     end
     def init_selected_lang_dirs(a)
-      @z=[]
-      a.each do |y|
+      @z=a.each.map do |y|
         if y =~/^#{lng_base}\/(\S+?\.ss[tm])$/
           @fn=$1
-          @z << y
+          y
         elsif y =~/^#{@lang_regx}\/?$/
-          @z << "#{y}/#{@fn}"
-        else @z << y
+          "#{y}/#{@fn}"
+        else y
         end
       end
-      @z
     end
     def init
       a=@a