aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorRalph Amissah <ralph@amissah.com>2015-03-19 18:38:21 -0400
committerRalph Amissah <ralph@amissah.com>2015-03-23 21:46:12 -0400
commit64dfdccbc0a136aab15c53ef0375244a28895429 (patch)
treed1cca15d22480dfb9e31765bd6160e72aab0c102
parentd: manifest add html ids to label/identify content (diff)
d: ao & elsewhere, use of map & select
-rw-r--r--data/doc/sisu/CHANGELOG_v62
-rw-r--r--lib/sisu/develop/ao_character_check.rb9
-rw-r--r--lib/sisu/develop/ao_composite.rb14
-rw-r--r--lib/sisu/develop/ao_doc_str.rb7
-rw-r--r--lib/sisu/develop/ao_endnotes.rb15
-rw-r--r--lib/sisu/develop/ao_hash_digest.rb8
-rw-r--r--lib/sisu/develop/ao_idx.rb7
-rw-r--r--lib/sisu/develop/ao_images.rb6
-rw-r--r--lib/sisu/develop/ao_misc_arrange.rb8
-rw-r--r--lib/sisu/develop/ao_numbering.rb16
-rw-r--r--lib/sisu/develop/cgi_sql_common.rb10
-rw-r--r--lib/sisu/develop/db_sqltxt.rb17
-rw-r--r--lib/sisu/develop/html_harvest_topics.rb6
-rw-r--r--lib/sisu/develop/html_tune.rb15
-rw-r--r--lib/sisu/develop/hub_loop_markup_files.rb3
-rw-r--r--lib/sisu/develop/hub_options.rb10
16 files changed, 64 insertions, 89 deletions
diff --git a/data/doc/sisu/CHANGELOG_v6 b/data/doc/sisu/CHANGELOG_v6
index d0745d6b..e51e0883 100644
--- a/data/doc/sisu/CHANGELOG_v6
+++ b/data/doc/sisu/CHANGELOG_v6
@@ -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)
diff --git a/lib/sisu/develop/ao_character_check.rb b/lib/sisu/develop/ao_character_check.rb
index b7cfc6df..2596c739 100644
--- a/lib/sisu/develop/ao_character_check.rb
+++ b/lib/sisu/develop/ao_character_check.rb
@@ -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
diff --git a/lib/sisu/develop/ao_composite.rb b/lib/sisu/develop/ao_composite.rb
index a60593d9..8a59f064 100644
--- a/lib/sisu/develop/ao_composite.rb
+++ b/lib/sisu/develop/ao_composite.rb
@@ -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__
diff --git a/lib/sisu/develop/ao_doc_str.rb b/lib/sisu/develop/ao_doc_str.rb
index 7f054660..c5f39ed4 100644
--- a/lib/sisu/develop/ao_doc_str.rb
+++ b/lib/sisu/develop/ao_doc_str.rb
@@ -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
diff --git a/lib/sisu/develop/ao_endnotes.rb b/lib/sisu/develop/ao_endnotes.rb
index c6dafd4c..c5233452 100644
--- a/lib/sisu/develop/ao_endnotes.rb
+++ b/lib/sisu/develop/ao_endnotes.rb
@@ -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
diff --git a/lib/sisu/develop/ao_hash_digest.rb b/lib/sisu/develop/ao_hash_digest.rb
index 97087a2a..39f34f85 100644
--- a/lib/sisu/develop/ao_hash_digest.rb
+++ b/lib/sisu/develop/ao_hash_digest.rb
@@ -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
diff --git a/lib/sisu/develop/ao_idx.rb b/lib/sisu/develop/ao_idx.rb
index 80dca601..cbe3f00c 100644
--- a/lib/sisu/develop/ao_idx.rb
+++ b/lib/sisu/develop/ao_idx.rb
@@ -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
diff --git a/lib/sisu/develop/ao_images.rb b/lib/sisu/develop/ao_images.rb
index 2e152573..e0f20d33 100644
--- a/lib/sisu/develop/ao_images.rb
+++ b/lib/sisu/develop/ao_images.rb
@@ -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
diff --git a/lib/sisu/develop/ao_misc_arrange.rb b/lib/sisu/develop/ao_misc_arrange.rb
index d474f553..8f8fe368 100644
--- a/lib/sisu/develop/ao_misc_arrange.rb
+++ b/lib/sisu/develop/ao_misc_arrange.rb
@@ -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
diff --git a/lib/sisu/develop/ao_numbering.rb b/lib/sisu/develop/ao_numbering.rb
index 6e9f2853..38054fa1 100644
--- a/lib/sisu/develop/ao_numbering.rb
+++ b/lib/sisu/develop/ao_numbering.rb
@@ -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 #!~/[.,:-]+/
diff --git a/lib/sisu/develop/cgi_sql_common.rb b/lib/sisu/develop/cgi_sql_common.rb
index 3974caf0..33e9c150 100644
--- a/lib/sisu/develop/cgi_sql_common.rb
+++ b/lib/sisu/develop/cgi_sql_common.rb
@@ -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
diff --git a/lib/sisu/develop/db_sqltxt.rb b/lib/sisu/develop/db_sqltxt.rb
index 86984596..1e3efbc7 100644
--- a/lib/sisu/develop/db_sqltxt.rb
+++ b/lib/sisu/develop/db_sqltxt.rb
@@ -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>")
diff --git a/lib/sisu/develop/html_harvest_topics.rb b/lib/sisu/develop/html_harvest_topics.rb
index bd461377..22c880d6 100644
--- a/lib/sisu/develop/html_harvest_topics.rb
+++ b/lib/sisu/develop/html_harvest_topics.rb
@@ -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,
diff --git a/lib/sisu/develop/html_tune.rb b/lib/sisu/develop/html_tune.rb
index 89757bb9..70c7e0ee 100644
--- a/lib/sisu/develop/html_tune.rb
+++ b/lib/sisu/develop/html_tune.rb
@@ -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
diff --git a/lib/sisu/develop/hub_loop_markup_files.rb b/lib/sisu/develop/hub_loop_markup_files.rb
index 541b205a..6b27b8d3 100644
--- a/lib/sisu/develop/hub_loop_markup_files.rb
+++ b/lib/sisu/develop/hub_loop_markup_files.rb
@@ -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],
diff --git a/lib/sisu/develop/hub_options.rb b/lib/sisu/develop/hub_options.rb
index 6e22c2ae..f6a40be9 100644
--- a/lib/sisu/develop/hub_options.rb
+++ b/lib/sisu/develop/hub_options.rb
@@ -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