From 0c80533993f1f8dfcb5a68e75ca49cd216dc68bd Mon Sep 17 00:00:00 2001 From: Ralph Amissah Date: Mon, 7 Jul 2014 01:21:51 -0400 Subject: v5 v6: ao, auto seg naming, adjustments * re: seg numbering, fixed width, leading zeros (introduced: 5.4.3 / 6.0.9) --- lib/sisu/v5/ao_numbering.rb | 23 +++++++++++++---------- lib/sisu/v5/constants.rb | 3 ++- lib/sisu/v6/ao_numbering.rb | 23 +++++++++++++---------- lib/sisu/v6/constants.rb | 3 ++- 4 files changed, 30 insertions(+), 22 deletions(-) (limited to 'lib') diff --git a/lib/sisu/v5/ao_numbering.rb b/lib/sisu/v5/ao_numbering.rb index 9fbaaab5..278ea514 100644 --- a/lib/sisu/v5/ao_numbering.rb +++ b/lib/sisu/v5/ao_numbering.rb @@ -308,27 +308,30 @@ module SiSU_AO_Numbering zeros_fixed_width=number_of_segments?.to_s.length zero_width=(zeros_fixed_width - nl) zero_width == 0 \ - ? Mx[:auto_seg_prefix] + - possible_seg_name.to_s - : Mx[:auto_seg_prefix] + - zero*zero_width + + ? possible_seg_name.to_s + : zero*zero_width + possible_seg_name.to_s end end - def auto_seg_name(possible_seg_name,heading_num_is) + def auto_seg_name(possible_seg_name,heading_num_is,type) + prefix=case type + when :auto then Mx[:segname_prefix_auto_num_provide] + when :extract then Mx[:segname_prefix_auto_num_extract] + else '_' #should not occur + end if possible_seg_name =~/^[0-9]+?\.$/m #!~/[.,:-]+/ possible_seg_name=possible_seg_name. gsub(/\.$/,'') end if possible_seg_name =~/^[0-9]+$/m \ and possible_seg_name.to_i <= heading_num_is.to_i - leading_zeros_fixed_width_number(possible_seg_name) + prefix + leading_zeros_fixed_width_number(possible_seg_name) elsif possible_seg_name =~/^[\d.,:-]+$/m possible_seg_name=possible_seg_name. gsub(/(?:[:,-]|\W)/,'.'). gsub(/\.$/,'') - #Mx[:auto_seg_prefix] + possible_seg_name - else possible_seg_name.to_s + prefix + possible_seg_name + else prefix + possible_seg_name.to_s end end def name_para_seg_filename(data) #segment naming, remaining @@ -369,7 +372,7 @@ module SiSU_AO_Numbering and dob.obj =~/^\s*(?:\S+\s+)?([\d.,:-]+)/m #heading starts with a recognised numeric or word followed by a recognised numeric construct, use that as name possible_seg_name=$1 possible_seg_name= - auto_seg_name(possible_seg_name,heading_num_is) + auto_seg_name(possible_seg_name,heading_num_is,:extract) possible_seg_name=possible_seg_name. gsub(/(?:[:,-]|\W)/,'.'). gsub(/\.$/,'') @@ -394,7 +397,7 @@ module SiSU_AO_Numbering if dob.ln==4 \ and not dob.name #if still no segment name, provide a numerical one possible_seg_name= - auto_seg_name(art_filename_auto,heading_num_is) + auto_seg_name(art_filename_auto,heading_num_is,:auto) if @md.seg_names.is_a?(Array) \ and not @md.seg_names.include?(possible_seg_name) dob.name=possible_seg_name diff --git a/lib/sisu/v5/constants.rb b/lib/sisu/v5/constants.rb index eb252fda..05678b32 100644 --- a/lib/sisu/v5/constants.rb +++ b/lib/sisu/v5/constants.rb @@ -104,7 +104,8 @@ Xx={ html_relative1: '※', } Mx={ - auto_seg_prefix: 's', + segname_prefix_auto_num_extract: 's', + segname_prefix_auto_num_provide: 's_', ocn_id_char: 'o', note: 'note_', note_ref: 'noteref_', diff --git a/lib/sisu/v6/ao_numbering.rb b/lib/sisu/v6/ao_numbering.rb index 755db795..ffafbf9c 100644 --- a/lib/sisu/v6/ao_numbering.rb +++ b/lib/sisu/v6/ao_numbering.rb @@ -308,27 +308,30 @@ module SiSU_AO_Numbering zeros_fixed_width=number_of_segments?.to_s.length zero_width=(zeros_fixed_width - nl) zero_width == 0 \ - ? Mx[:auto_seg_prefix] + - possible_seg_name.to_s - : Mx[:auto_seg_prefix] + - zero*zero_width + + ? possible_seg_name.to_s + : zero*zero_width + possible_seg_name.to_s end end - def auto_seg_name(possible_seg_name,heading_num_is) + def auto_seg_name(possible_seg_name,heading_num_is,type) + prefix=case type + when :auto then Mx[:segname_prefix_auto_num_provide] + when :extract then Mx[:segname_prefix_auto_num_extract] + else '_' #should not occur + end if possible_seg_name =~/^[0-9]+?\.$/m #!~/[.,:-]+/ possible_seg_name=possible_seg_name. gsub(/\.$/,'') end if possible_seg_name =~/^[0-9]+$/m \ and possible_seg_name.to_i <= heading_num_is.to_i - leading_zeros_fixed_width_number(possible_seg_name) + prefix + leading_zeros_fixed_width_number(possible_seg_name) elsif possible_seg_name =~/^[\d.,:-]+$/m possible_seg_name=possible_seg_name. gsub(/(?:[:,-]|\W)/,'.'). gsub(/\.$/,'') - #Mx[:auto_seg_prefix] + possible_seg_name - else possible_seg_name.to_s + prefix + possible_seg_name + else prefix + possible_seg_name.to_s end end def name_para_seg_filename(data) #segment naming, remaining @@ -369,7 +372,7 @@ module SiSU_AO_Numbering and dob.obj =~/^\s*(?:\S+\s+)?([\d.,:-]+)/m #heading starts with a recognised numeric or word followed by a recognised numeric construct, use that as name possible_seg_name=$1 possible_seg_name= - auto_seg_name(possible_seg_name,heading_num_is) + auto_seg_name(possible_seg_name,heading_num_is,:extract) possible_seg_name=possible_seg_name. gsub(/(?:[:,-]|\W)/,'.'). gsub(/\.$/,'') @@ -394,7 +397,7 @@ module SiSU_AO_Numbering if dob.ln==4 \ and not dob.name #if still no segment name, provide a numerical one possible_seg_name= - auto_seg_name(art_filename_auto,heading_num_is) + auto_seg_name(art_filename_auto,heading_num_is,:auto) if @md.seg_names.is_a?(Array) \ and not @md.seg_names.include?(possible_seg_name) dob.name=possible_seg_name diff --git a/lib/sisu/v6/constants.rb b/lib/sisu/v6/constants.rb index d25478d1..53ed226a 100644 --- a/lib/sisu/v6/constants.rb +++ b/lib/sisu/v6/constants.rb @@ -104,7 +104,8 @@ Xx={ html_relative1: '※', } Mx={ - auto_seg_prefix: 's', + segname_prefix_auto_num_extract: 's', + segname_prefix_auto_num_provide: 's_', ocn_id_char: 'o', note: 'note_', note_ref: 'noteref_', -- cgit v1.2.3