aboutsummaryrefslogtreecommitdiffhomepage
path: root/lib/sisu/v4
diff options
context:
space:
mode:
authorRalph Amissah <ralph@amissah.com>2013-10-27 23:27:13 -0400
committerRalph Amissah <ralph@amissah.com>2013-10-27 23:27:13 -0400
commitd08020e7b2cfd7cabc3b5d0aa18e5d07465ecfc6 (patch)
tree78992a0e8eb27cd43bc9784a894d6d6b4554d193 /lib/sisu/v4
parentv4 v5: cleaning, minor (diff)
v4 v5: dal, document_structure_check_infosisu_4.2.9
Diffstat (limited to 'lib/sisu/v4')
-rw-r--r--lib/sisu/v4/dal_doc_str.rb118
1 files changed, 102 insertions, 16 deletions
diff --git a/lib/sisu/v4/dal_doc_str.rb b/lib/sisu/v4/dal_doc_str.rb
index 8a177569..f9dd4954 100644
--- a/lib/sisu/v4/dal_doc_str.rb
+++ b/lib/sisu/v4/dal_doc_str.rb
@@ -796,12 +796,71 @@ module SiSU_DAL_DocumentStructureExtract
def initialize(md,data)
@md,@data=md,data
end
+ def structure_info
+ def lv
+ %w[0 A~ B~ C~ 1 2 3]
+ end
+ def possible_parents(child)
+ case child
+ when /A~/
+ 'none'
+ when /B~/
+ 'A~'
+ when /C~/
+ 'B~'
+ when /1/
+ 'A~, B~, C~'
+ when /2/
+ '1'
+ when /3/
+ '3'
+ end
+ end
+ def possible_children(parent)
+ case parent
+ when /A~/
+ 'B~, 1'
+ when /B~/
+ 'C~, 1'
+ when /C~/
+ '1'
+ when /1/
+ '2'
+ when /2/
+ '3'
+ when /3/
+ 'none'
+ end
+ end
+ self
+ end
+ def document_structure_check_info(node,node_parent,status=:ok)
+ node_ln=/^([0-6])/.match(node)[1].to_i
+ node_parent_ln=/^([0-6])/.match(node_parent)[1].to_i
+ if status==:error \
+ or @md.opt.act[:maintenance][:set]==:on
+ puts %{node: #{node}, parent node: #{node_parent} #{status.upcase}}
+ if status==:error
+ node_ln=/^([0-6])/.match(node)[1].to_i
+ node_parent_ln=/^([0-6])/.match(node_parent)[1].to_i
+ puts %{current level: #{structure_info.lv[node_ln]} (possible parent levels: #{structure_info.possible_parents(structure_info.lv[node_ln])})
+parent level: #{structure_info.lv[node_parent_ln]} (possible child levels: #{structure_info.possible_children(structure_info.lv[node_parent_ln])})
+-- }
+ end
+ end
+ end
+ def warning_incorrect_parent_level_or_level(txt)
+ puts %{warning,
+#{txt}
+has incorrect level and/or parent level}
+ end
def ocn #and auto segment numbering increment
data=@data
@o_array=[]
node=ocn=ocn_dv=ocn_sp=ocnh=ocnh1=ocnh2=ocnh3=ocnh4=ocnh5=ocnh6=ocno=ocnp=ocnt=ocnc=ocng=ocni=ocnu=0 # h heading, o other, t table, g group, i image
regex_exclude_ocn_and_node = /#{Rx[:meta]}|^@\S+?:\s|^4~endnotes|^#{Mx[:lv_o]}4:endnotes#{Mx[:lv_c]}|^\^~ |<:e[:_]\d+?>|^<:\#|<:- |<[:!]!4|<hr width|#{Mx[:br_endnotes]}|\A\s*\Z/mi #ocn here #&nbsp; added with Tune.code #ยก
parent=node1=node2=node3=node4=node5=node6=nil
+ node0='0:0;0'
@collapsed_lv1=1
data.each do |dob|
h={}
@@ -840,17 +899,20 @@ module SiSU_DAL_DocumentStructureExtract
if ln==1 \
or ln=~@md.lv1; ocnh1+=1 #heading
node1="1:#{ocnh1};#{ocn}"
+ document_structure_check_info(node1,node0)
@collapsed_lv1=1
collapsed_level=@collapsed_lv1
- node,ocn_sp,parent=node1,"h#{ocnh}",0 #FIX
+ node,ocn_sp,parent=node1,"h#{ocnh}",node0 #FIX
elsif ln==2 \
or ln=~@md.lv2; ocnh2+=1
node2="2:#{ocnh2};#{ocn}"
parent=if node1
+ document_structure_check_info(node2,node1)
@collapsed_lv2=@collapsed_lv1+1
node1
else
- 0
+ document_structure_check_info(node2,node0,:error)
+ node0
end
collapsed_level=@collapsed_lv2
node,ocn_sp=node2,"h#{ocnh}"
@@ -858,15 +920,21 @@ module SiSU_DAL_DocumentStructureExtract
or ln=~@md.lv3; ocnh3+=1
node3="3:#{ocnh3};#{ocn}"
parent=if node2
+ document_structure_check_info(node3,node2)
@collapsed_lv3=@collapsed_lv2+1
node2
elsif node1
- puts "warning, incorrect parent or node level, parent is :A~ parent should be :B~ else this node should be :B~ rather than :C~" unless @md.opt.cmd=~/q/
+ warning_incorrect_parent_level_or_level(dob.obj)
+ puts %{parent is :A~ & this level #{dob.lv}
+either parent should be level :B~
+or this level should be level :B~ rather than #{dob.lv}}
+ document_structure_check_info(node3,node1,:error)
@collapsed_lv3=@collapsed_lv1+1
node1
else
- puts "warning, incorrect node and or parent level" unless @md.opt.cmd=~/q/
- 0
+ document_structure_check_info(node3,node0,:error)
+ warning_incorrect_parent_level_or_level(dob.obj)
+ node0
end
collapsed_level=@collapsed_lv3
node,ocn_sp=node3,"h#{ocnh}"
@@ -874,17 +942,21 @@ module SiSU_DAL_DocumentStructureExtract
or ln=~@md.lv4; ocnh4+=1
node4="4:#{ocnh4};#{ocn}"
parent=if node3
+ document_structure_check_info(node4,node3)
@collapsed_lv4=@collapsed_lv3+1
node3
elsif node2
+ document_structure_check_info(node4,node2)
@collapsed_lv4=@collapsed_lv2+1
node2
elsif node1
+ document_structure_check_info(node4,node1)
@collapsed_lv4=@collapsed_lv1+1
node1
else
- puts "warning, incorrect node and or parent level" unless @md.opt.cmd=~/q/
- 0
+ warning_incorrect_parent_level_or_level(dob.obj)
+ document_structure_check_info(node4,node0,:error)
+ node0
end
collapsed_level=@collapsed_lv4
node,ocn_sp=node4,"h#{ocnh}"
@@ -892,22 +964,27 @@ module SiSU_DAL_DocumentStructureExtract
or ln=~@md.lv5; ocnh5+=1
node5="5:#{ocnh5};#{ocn}"
parent=if node4
+ document_structure_check_info(node5,node4)
@collapsed_lv5=@collapsed_lv4+1
node4
elsif node3
- puts "warning, incorrect node and or parent level" unless @md.opt.cmd=~/q/
+ warning_incorrect_parent_level_or_level(dob.obj)
+ document_structure_check_info(node5,node3,:error)
@collapsed_lv5=@collapsed_lv3+1
node3
elsif node2
- puts "warning, incorrect node and or parent level" unless @md.opt.cmd=~/q/
+ warning_incorrect_parent_level_or_level(dob.obj)
+ document_structure_check_info(node5,node2,:error)
@collapsed_lv5=@collapsed_lv2+1
node2
elsif node1
- puts "warning, incorrect node and or parent level" unless @md.opt.cmd=~/q/
+ warning_incorrect_parent_level_or_level(dob.obj)
+ document_structure_check_info(node5,node1,:error)
@collapsed_lv5=@collapsed_lv1+1
node1
else
- 0
+ document_structure_check_info(node5,node0,:error)
+ node0
end
collapsed_level=@collapsed_lv5
node,ocn_sp=node5,"h#{ocnh}"
@@ -915,26 +992,35 @@ module SiSU_DAL_DocumentStructureExtract
or ln=~@md.lv6; ocnh6+=1
node6="6:#{ocnh6};#{ocn}"
parent=if node5
+ document_structure_check_info(node6,node5)
@collapsed_lv6=@collapsed_lv5+1
node5
elsif node4
- puts "warning, incorrect parent or node level, parent is 4~ parent should be 5~ else this node should be 5~ rather than 6~" unless @md.opt.cmd=~/q/
+ warning_incorrect_parent_level_or_level(dob.obj)
+ puts "parent is level 4~ & this level #{dob.lv}
+either parent should be level 5~
+or this level should be 5~ rather #{dob.lv}" #level 6
+ document_structure_check_info(node6,node4,:error)
@collapsed_lv6=@collapsed_lv4+1
node4
elsif node3
- puts "warning, incorrect node and or parent level" unless @md.opt.cmd=~/q/
+ warning_incorrect_parent_level_or_level(dob.obj)
+ document_structure_check_info(node6,node3,:error)
@collapsed_lv6=@collapsed_lv3+1
node3
elsif node2
- puts "warning, incorrect node and or parent level" unless @md.opt.cmd=~/q/
+ warning_incorrect_parent_level_or_level(dob.obj)
+ document_structure_check_info(node6,node2,:error)
@collapsed_lv6=@collapsed_lv2+1
node2
elsif node1
- puts "warning, incorrect node and or parent level" unless @md.opt.cmd=~/q/
+ warning_incorrect_parent_level_or_level(dob.obj)
+ document_structure_check_info(node6,node1,:error)
@collapsed_lv6=@collapsed_lv1+1
node1
else
- 0
+ document_structure_check_info(node6,node0,:error)
+ node0
end
collapsed_level=@collapsed_lv6
node,ocn_sp=node6,"h#{ocnh}"