Module: SUMD_Symbols
- Defined in:
- lib/su_info/sumd_symbols.rb
Overview
Purpose:
Creates an md file of most of the symbols defined in SketchUp. Root constants are not listed, but can be found in the 'Constants List'.
Required files:
File name | Information / Notes |
---|---|
Template_Symbols.md | markdown template |
native_ruby_syms.txt | contains symbols native to Ruby |
su??_constants_tab_md.txt |
used to remove some constants from the symbols list. |
Class Method Summary collapse
-
.sumd__run
Main entry point.
-
.sumd_found_txt ⇒ String
Returns a string with the quantities of constant types found.
-
.sumd_lwr_attr
Loads @attrs, removes items from @sym_f_lwr.
-
.sumd_md__attr
Loads 'atrribute' table data into md text.
-
.sumd_md__list(list, sumd_name)
Loads lists / arrays into md @text_md.
-
.sumd_split_list(a, idx, r) ⇒ Array<Integer,Integer>
Adds blank lines for alpha splits, returns 2 column split info.
-
.sumd_txt_list(list)
Loads lists / arrays into text @text.
Class Method Details
.sumd__run
Main entry point
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/su_info/sumd_symbols.rb', line 46 def self.sumd__run return unless ( @text_md = SUMD.sumd_file_read('Template_Symbols.md') ) return unless ( @constants = SUMD.sumd_file_read("su#{@su_major}_constants_tab_md.txt") ) # get hash from file of native Ruby symbols @h_native = {} return unless SUMD::sumd_get_ruby_hash(@h_native, true) @constants.gsub!(/[\s]{2,}/, "\n") # load @rt_cnsts hash with root constant names @rt_cnsts = {} while (sumd_match = @constants.slice!(/^[^\t]+/) ) do @rt_cnsts[sumd_match] = nil unless (/::/ === sumd_match) end @constants = nil @sym_attr = [] @sym_up = [] @sym_f_up = [] @sym_f_lwr = [] @sym_glbl = [] Symbol.all_symbols.each { |x| s = x.to_s next if @h_native.key?(s) || @rt_cnsts.key?(s) || (/^sumd/i === s) next if s == '' if (/^[a-z0-9_]/ =~ s) ; @sym_f_lwr << ":#{s}" elsif (s.upcase == s) ; @sym_up << ":#{s}" elsif (/^[^@$]/ =~ s) ; @sym_f_up << ":#{s}" elsif (/^\$/ =~ s) ; @sym_glbl << "#{s}" end } @sym_f_lwr.sort! @sym_f_up.sort! @sym_up.sort! @sym_glbl.sort! # puts @sym_glbl.join("\n") # puts "@sym_up.join" # puts @sym_up.join("\n") @ctr_attr = 0 sumd_lwr_attr() sumd_md__attr() if @attrs.length > 0 @text_md.sub!(/<%= found %>/, sumd_found_txt() ) sumd_txt_list(@sym_f_lwr) sumd_md__list(@sym_f_lwr , '_method' ) sumd_txt_list(@sym_f_up) sumd_md__list(@sym_f_up , '_class' ) sumd_txt_list(@sym_up) sumd_md__list(@sym_up , '_constant') @text_md.sub!(/<%= hdr %>/, SUMD.sumd_generated_by(name, @version)) files = [] files << SUMD.sumd_file_write('Symbols.md' , @text_md) files << SUMD.sumd_file_write('symbols.txt', @text) puts "-------------------------------------------------\n" \ "#{name} wrote the following files:\n#{files.join(10.chr)}\n" end |
.sumd_found_txt ⇒ String
Returns a string with the quantities of constant types found.
319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 |
# File 'lib/su_info/sumd_symbols.rb', line 319 def self.sumd_found_txt() n = '  ' a = @ctr_attr low = @sym_f_lwr.length up = @sym_f_up.length upcase = @sym_up.length t = (a + low + up + upcase).to_s.gsub(/(\d)(?=(\d{3})+(?!\d))/, "\\1,") a = a.to_s.rjust(3).gsub(/ /, n) low = low.to_s.rjust(3).gsub(/ /, n) up = up.to_s.rjust(3).gsub(/ /, n) upcase = upcase.to_s.rjust(3).gsub(/ /, n) "Found #{t} symbols, listed as follows:\n\n" \ "* #{a } as attribute names\n" \ "* #{low } with lower case 1st letter\n" \ "* #{up } with upper case 1st letter\n" \ "* #{upcase } with all upper case lettering" end |
.sumd_lwr_attr
Loads @attrs, removes items from @sym_f_lwr
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 |
# File 'lib/su_info/sumd_symbols.rb', line 118 def self.sumd_lwr_attr() @attrs = [] a = @sym_f_lwr a << '' a << '' line = 0 i = 0 while (a[i] != '') do v = a[i] s = nil break if (v == '') del = false if (/#{v}[\?\=]/ === a[i+1] ) y = a[i+1] z = a[i+2] del = true if (/\?$/ === y ) s = ['?', ' ', "#{v}"] @text << "#{v}\t\t#{y}" @ctr_attr += 2 else s = [' ', '=', "#{v}"] @text << "#{v}\t#{y}" @ctr_attr += 2 if (/#{v}\?/ === z ) s[0] = '?' @text << "\t#{z}" @ctr_attr += 1 a.delete_at(i+2) end end else if (/\?$/ === v ) s = [' ', ' ', "#{v}"] @text << "#{v}" @ctr_attr += 1 a.delete_at(i) @text << "\n" i -= 1 line += 1 @text << "\n" if line % 5 == 0 end end if (del) a.delete_at(i+1) a.delete_at(i) @text << "\n" i -= 1 line += 1 @text << "\n" if line % 5 == 0 end i += 1 @attrs << s if s end @text << "\n" a.pop a.pop end |
.sumd_md__attr
Loads 'atrribute' table data into md text
248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 |
# File 'lib/su_info/sumd_symbols.rb', line 248 def self.sumd_md__attr() # add blank 'lines' for alphabet grouping, find split length = sumd_split_list(@attrs, 2, [' ', ' ', ' ']) len = @attrs.length tt = "<thead><tr>\n" \ "<th class='c'>B</th><th class='c'>W</th><th> Attribute</th><th></th>" \ "<th class='c'>B</th><th class='c'>W</th><th> Attribute</th>" \ "</tr><tbody>\n" b = [' ', ' ', ' '] 0.upto(length[0]) { |i| e1 = ( i < length[1] ? @attrs[i] : b ) e2 = ( i + length[1] < len ? @attrs[i + length[1]] : b ) tt << "<tr><td class='c'>#{e1[0]}</td><td class='c'>#{e1[1]}</td>" \ "<td>#{e1[2]}</td><td> </td><td class='c'>#{e2[0]}</td>" \ "<td class='c'>#{e2[1]}</td><td>#{e2[2]}</td></tr>\n" } tt << "</tbody>\n" @text_md.sub!(/<%= _attribute %>/, tt) end |
.sumd_md__list(list, sumd_name)
Loads lists / arrays into md @text_md
273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 |
# File 'lib/su_info/sumd_symbols.rb', line 273 def self.sumd_md__list(list, sumd_name) # add blank 'lines' for alphabet grouping, find split t = sumd_split_list(list, -1, ' ') list.insert(t[1], ' ') tt = '' tt << @b_h_3 sub = [] while (list.length > 0) do a1 = 0 a2 = 0 0.upto(list.length - 1) { |i| a1 = a2 a2 = i if list[i] == ' ' if (a1 > 20) && (a2 - a1) > 30 # send a1 to text sub = list.slice!(0, a1) list.slice!(0) break elsif a2 > 50 sub = list.slice!(0, a2) list.slice!(0) break elsif i == list.length - 1 sub = list.slice!(0, list.length) end } break if sub.length == 0 len = sub.length split = ( 0.5 * (len + 1) ).floor 0.upto(split - 1) { |i| e1 = sub[i] e2 = ( i + split < len ? sub[i + split] : ' ' ) tt << "<tr><td>#{e1}</td><td> </td><td>#{e2}</td></tr>\n" tt << @b_l_3 if ( (i+1) % 5 == 0 && (i != split - 1) ) } tt << @empty + @empty + @b_h_3 + @empty end tt << "</tbody>\n" @text_md.sub!(/<%= #{sumd_name} %>/, tt) end |
.sumd_split_list(a, idx, r) ⇒ Array<Integer,Integer>
Adds blank lines for alpha splits, returns 2 column split info
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 |
# File 'lib/su_info/sumd_symbols.rb', line 184 def self.sumd_split_list(a, idx, r) # add blank 'lines' for alphabet grouping len = a.length - 2 len.downto(0) { |i| if (idx >= 0) if a[i][idx].slice(1,1) != a[i+1][idx].slice(1,1) a.insert(i+1, r) end else if a[i].slice(1,1) != a[i+1].slice(1,1) a.insert(i+1, r) end end } # find split info len = a.length split = ( 0.5 * (a.length + 1) ).floor upto = len downto = 0 split.upto(len) { |i| if (idx >= 0) if a[i][idx] == ' ' upto = i break end else if a[i] == ' ' upto = i break end end } split.downto(0) { |i| if (idx >= 0) if a[i][idx] == ' ' downto = i break end else if a[i] == ' ' downto = i break end end } # puts "downto = #{downto} upto = #{upto} split = #{split}" if (split - downto) > (upto - split) # use upto, second column shorter a.delete_at(upto) length = [upto - 1, upto] else # use downto, second column longer a.delete_at(downto) len = a.length length = [len - downto - 1, downto] end length end |
.sumd_txt_list(list)
Loads lists / arrays into text @text
344 345 346 347 348 349 350 351 352 |
# File 'lib/su_info/sumd_symbols.rb', line 344 def self.sumd_txt_list(list) count = 0 list.each { |s| @text << "#{s}\n" count += 1 @text << "\n" if count % 5 == 0 } @text << "\n" end |