Class: SiSU_AO_DocumentStructureExtract::XML

Inherits:
Object
  • Object
show all
Defined in:
lib/sisu/ao_doc_str.rb

Instance Method Summary collapse

Constructor Details

#initialize(md, data) ⇒ XML

Returns a new instance of XML.



1915
1916
1917
# File 'lib/sisu/ao_doc_str.rb', line 1915

def initialize(md,data)
  @data,@md=data,md
end

Instance Method Details

#domObject



1918
1919
1920
1921
1922
# File 'lib/sisu/ao_doc_str.rb', line 1918

def dom
  @s=[ 'A', 'B', 'C', 'D', '1', '2', '3' ]
  tuned_file=structure_build
  tuned_file
end

#puts_tag_close(lev, hs) ⇒ Object



2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
# File 'lib/sisu/ao_doc_str.rb', line 2251

def puts_tag_close(lev,hs)
  case hs[0]
  when 0
    #puts "#{spaces*0}</#{@s[0]}>" if (lev <= 0) and hs[0]
    puts "</#{@s[0]}>"         if (lev==0)
  when 1
    puts "#{spaces*1}</#{@s[1]}>" if (lev <= 1) and hs[1]
    puts "</#{@s[0]}>"         if (lev==0)
  when 2
    puts "#{spaces*2}</#{@s[2]}>" if (lev <= 2) and hs[2]
    puts "#{spaces*1}</#{@s[1]}>" if (lev <= 1) and hs[1]
    puts "</#{@s[0]}>"         if (lev==0)
  when 3
    puts "#{spaces*3}</#{@s[3]}>" if (lev <= 3) and hs[3]
    puts "#{spaces*2}</#{@s[2]}>" if (lev <= 2) and hs[2]
    puts "#{spaces*1}</#{@s[1]}>" if (lev <= 1) and hs[1]
    puts "</#{@s[0]}>"         if (lev==0)
  when 4
    puts "#{spaces*4}</#{@s[4]}>" if (lev <= 4)
    puts "#{spaces*3}</#{@s[3]}>" if (lev <= 3) and hs[3]
    puts "#{spaces*2}</#{@s[2]}>" if (lev <= 2) and hs[2]
    puts "#{spaces*1}</#{@s[1]}>" if (lev <= 1) and hs[1]
    puts "</#{@s[0]}>"         if (lev==0)
  when 5
    puts "#{spaces*5}</#{@s[5]}>" if (lev <= 5)
    puts "#{spaces*4}</#{@s[4]}>" if (lev <= 4)
    puts "#{spaces*3}</#{@s[3]}>" if (lev <= 3) and hs[3]
    puts "#{spaces*2}</#{@s[2]}>" if (lev <= 2) and hs[2]
    puts "#{spaces*1}</#{@s[1]}>" if (lev <= 1) and hs[1]
    puts "</#{@s[0]}>"         if (lev==0)
  when 6
    puts "#{spaces*6}</#{@s[6]}>" if (lev <= 6)
    puts "#{spaces*5}</#{@s[5]}>" if (lev <= 5)
    puts "#{spaces*4}</#{@s[4]}>" if (lev <= 4)
    puts "#{spaces*3}</#{@s[3]}>" if (lev <= 3) and hs[3]
    puts "#{spaces*2}</#{@s[2]}>" if (lev <= 2) and hs[2]
    puts "#{spaces*1}</#{@s[1]}>" if (lev <= 1) and hs[1]
    puts "</#{@s[0]}>"         if (lev==0)
  end
end

#puts_tag_open(o, tag) ⇒ Object



2248
2249
2250
# File 'lib/sisu/ao_doc_str.rb', line 2248

def puts_tag_open(o,tag)
  puts %{#{spaces*o.ln}<#{tag[o.ln]} id="#{o.node}">}
end

#spacesObject



1923
1924
1925
# File 'lib/sisu/ao_doc_str.rb', line 1923

def spaces
  Ax[:spaces]
end

#structure_buildObject



1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
# File 'lib/sisu/ao_doc_str.rb', line 1926

def structure_build
  data=@data
  tuned_file=[]
  hs=[0,false,false,false]
  t={
    lv: @s[0],
    status: :open,
  }
  tuned_file << tags(t)
  if @md.opt.act[:verbose_plus][:set]==:on
    puts "\nXML sisu structure outline --->\n"
    puts "<#{@s[0]}>"
  end
  data.each_with_index do |o,i|
    if o.is==:heading \
    || o.is==:heading_insert
      case o.ln
      when 0
        tuned_file << tag_close(o.ln,hs)
        tuned_file << tag_open(o,@s)
        if @md.opt.act[:verbose_plus][:set]==:on
          puts_tag_close(o.ln,hs)
          puts_tag_open(o,@s)
        end
        hs=[0,true,false,false,false]
      when 1
        tuned_file << tag_close(o.ln,hs)
        tuned_file << tag_open(o,@s)
        if @md.opt.act[:verbose_plus][:set]==:on
          puts_tag_close(o.ln,hs)
          puts_tag_open(o,@s)
        end
        hs=[1,true,true,false,false]
      when 2
        tuned_file << tag_close(o.ln,hs)
        tuned_file << tag_open(o,@s)
        if @md.opt.act[:verbose_plus][:set]==:on
          puts_tag_close(o.ln,hs)
          puts_tag_open(o,@s)
        end
        hs=[2,true,true,true,false]
      when 3
        tuned_file << tag_close(o.ln,hs)
        tuned_file << tag_open(o,@s)
        if @md.opt.act[:verbose_plus][:set]==:on
          puts_tag_close(o.ln,hs)
          puts_tag_open(o,@s)
        end
        hs=[3,true,true,true,true]
      when 4
        tuned_file << tag_close(o.ln,hs)
        tuned_file << tag_open(o,@s)
        if @md.opt.act[:verbose_plus][:set]==:on
          puts_tag_close(o.ln,hs)
          puts_tag_open(o,@s)
        end
        hs[0]=4
      when 5
        tuned_file << tag_close(o.ln,hs)
        tuned_file << tag_open(o,@s)
        if @md.opt.act[:verbose_plus][:set]==:on
          puts_tag_close(o.ln,hs)
          puts_tag_open(o,@s)
        end
        hs[0]=5
      when 6
        tuned_file << tag_close(o.ln,hs)
        tuned_file << tag_open(o,@s)
        if @md.opt.act[:verbose_plus][:set]==:on
          puts_tag_close(o.ln,hs)
          puts_tag_open(o,@s)
        end
        hs[0]=6
      end
    end
    tuned_file << o
  end
  if @md.opt.act[:verbose_plus][:set]==:on
    puts_tag_close(0,hs)
  end
  tuned_file << tag_close(0,hs)
  tuned_file=tuned_file.flatten
end

#tag_close(lev, hs) ⇒ Object



2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
# File 'lib/sisu/ao_doc_str.rb', line 2039

def tag_close(lev,hs)
  ary=[]
  case hs[0]
  when 0
    if (lev <= 0) and hs[0]
      t={
        lv: @s[0],
        status: :close,
      }
      ary << tags(t)
    end
  when 1
    if (lev <= 1) and hs[1]
      t={
        lv: @s[1],
        status: :close,
      }
      ary << tags(t)
    end
    if (lev==0)
      t={
        lv: @s[0],
        status: :close,
      }
      ary << tags(t)
    end
  when 2
    if (lev <= 2) and hs[2]
      t={
        lv: @s[2],
        status: :close,
      }
      ary << tags(t)
    end
    if (lev <= 1) and hs[1]
      t={
        lv: @s[1],
        status: :close,
      }
      ary << tags(t)
    end
    if (lev==0)
      t={
        lv: @s[0],
        status: :close,
      }
      ary << tags(t)
    end
  when 3
    if (lev <= 3) and hs[3]
      t={
        lv: @s[3],
        status: :close,
      }
      ary << tags(t)
    end
    if (lev <= 2) and hs[2]
      t={
        lv: @s[2],
        status: :close,
      }
      ary << tags(t)
    end
    if (lev <= 1) and hs[1]
      t={
        lv: @s[1],
        status: :close,
      }
      ary << tags(t)
    end
    if (lev==0)
      t={
        lv: @s[0],
        status: :close,
      }
      ary << tags(t)
    end
  when 4
    if (lev <= 4)
      t={
        lv: @s[4],
        status: :close,
      }
      ary << tags(t)
    end
    if (lev <= 3) and hs[3]
      t={
        lv: @s[3],
        status: :close,
      }
      ary << tags(t)
    end
    if (lev <= 2) and hs[2]
      t={
        lv: @s[2],
        status: :close,
      }
      ary << tags(t)
    end
    if (lev <= 1) and hs[1]
      t={
        lv: @s[1],
        status: :close,
      }
      ary << tags(t)
    end
    if (lev==0)
      t={
        lv: @s[0],
        status: :close,
      }
      ary << tags(t)
    end
  when 5
    if (lev <= 5)
      t={
        lv: @s[5],
        status: :close,
      }
      ary << tags(t)
    end
    if (lev <= 4)
      t={
        lv: @s[4],
        status: :close,
      }
      ary << tags(t)
    end
    if (lev <= 3) and hs[3]
      t={
        lv: @s[3],
        status: :close,
      }
      ary << tags(t)
    end
    if (lev <= 2) and hs[2]
      t={
        lv: @s[2],
        status: :close,
      }
      ary << tags(t)
    end
    if (lev <= 1) and hs[1]
      t={
        lv: @s[1],
        status: :close,
      }
      ary << tags(t)
    end
    if (lev==0)
      t={
        lv: @s[0],
        status: :close,
      }
      ary << tags(t)
    end
  when 6
    if (lev <= 6)
      t={
        lv: @s[6],
        status: :close,
      }
      ary << tags(t)
    end
    if (lev <= 5)
      t={
        lv: @s[5],
        status: :close,
      }
      ary << tags(t)
    end
    if (lev <= 4)
      t={
        lv: @s[4],
        status: :close,
      }
      ary << tags(t)
    end
    if (lev <= 3) and hs[3]
      t={
        lv: @s[3],
        status: :close,
      }
      ary << tags(t)
    end
    if (lev <= 2) and hs[2]
      t={
        lv: @s[2],
        status: :close,
      }
      ary << tags(t)
    end
    if (lev <= 1) and hs[1]
      t={
        lv: @s[1],
        status: :close,
      }
      ary << tags(t)
    end
    if (lev==0)
      t={
        lv: @s[0],
        status: :close,
      }
      ary << tags(t)
    end
  end
  ary
end

#tag_open(o, tag) ⇒ Object



2034
2035
2036
2037
2038
# File 'lib/sisu/ao_doc_str.rb', line 2034

def tag_open(o,tag)
  t={ lv: tag[o.ln], node: o.node, status: :open }
  t_o=tags(t)
  t_o
end

#tags(o) ⇒ Object



2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
# File 'lib/sisu/ao_doc_str.rb', line 2009

def tags(o)
  tag=(o[:status]==:open) \
  ? %{<#{o[:lv]} id="#{o[:node]}">}
  : "</#{o[:lv]}>"
  ln=case o[:lv]
  when 'A' then 0
  when 'B' then 1
  when 'C' then 2
  when 'D' then 3
  when '1' then 4
  when '2' then 5
  when '3' then 6
  when '4' then 7
  when '5' then 8
  when '6' then 9
  end
  h={
    tag: tag,
    node: o[:node],
    lv: o[:lv],
    ln: ln,
    status: o[:status],
  }
  SiSU_AO_DocumentStructure::ObjectStructure.new.xml_dom(h) #downstream code utilise else ignore like comments
end