Module: SUMD_Collections
- Defined in:
- lib/su_info/sumd_collections.rb
Overview
Purpose:
Creates an md file of the collections defined in SketchUp classes
Required files:
File name | Information / Notes |
---|---|
Template_Collections.md | markdown template |
native_ruby_cnsts.txt | contains 'root' constants native to Ruby |
Code Process:
- Loop thru
Object.constants
, creating an array of module / class obects defined by SketchUp. Requires the file native_ruby_cnsts.txt to determine what constants are native to Ruby. - Adds collections to file text Template_Collections.md.
- Calls .find_nested and processes namespaced collections.
Lastly, remember to unload all of your extensions / plug-ins before runnning this.
Class Method Summary collapse
-
._run
Main entry point.
-
.add_row(obj, isCls)
Adds a row to the table / list.
-
.done
Inserts data into md template, writes file.
-
.find_nested(obj)
Finds all collections in object namespace, reentrant.
Class Method Details
._run
Main entry point
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 |
# File 'lib/su_info/sumd_collections.rb', line 60 def self._run() # get template return unless (@text_md = SUMD.sumd_file_read('Template_Collections.md')) # get hash from file of native Ruby objects h_native = {} return unless SUMD.sumd_get_ruby_hash(h_native) # find objects and process objects = [] Object.constants.sort.each { |c| o = Object.const_get(c) c_to_s = c.to_s next if ( /^SUMD/ =~ c_to_s || h_native.key?(c_to_s) ) objects << o if ( o.is_a?(Module) ) } # process root modules / classes if (objects.length > 0) # sort with Sketchup first objects.delete(Object) objects.delete(Sketchup) objects.sort! { |a,b| a.to_s <=> b.to_s } objects.insert(0, Sketchup) # now find info on modules / classes objects.each { |o| find_nested(o) } end done() end |
.add_row(obj, isCls)
Adds a row to the table / list
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 |
# File 'lib/su_info/sumd_collections.rb', line 119 def self.add_row(obj, isCls) super_cls = isCls ? obj.superclass : "not defined" obj_str = obj.to_s if (/(::)?([^:]+)$/ === obj_str) obj_str = "<a href='#{@su_docs}#{$2.downcase}'>#{obj_str}</a>" if $2 end _enum = obj.include?(Enumerable) _each = obj.public_method_defined?(:each) _brackets = obj.public_method_defined?(:[]) _brackets_eq = obj.public_method_defined?(:[]=) _each_pair = obj.public_method_defined?(:each_pair) # cascades _each_pair = (_each_pair && _brackets_eq) ? 'Y' : ( _each_pair ? 'Yes' : ' ') _brackets_eq = (_brackets_eq && _brackets ) ? 'Y' : ( _brackets_eq ? 'Yes' : ' ') _brackets = (_brackets && _each ) ? 'Y' : ( _brackets ? 'Yes' : ' ') _each = (_each && _enum ) ? 'Y' : ( _each ? 'Yes' : ' ') _enum = (_enum ? 'Yes' : ' ') @text << "<tr><td>#{obj_str}</td>" \ "<td class='c'>#{_enum}</td>" \ "<td class='c'>#{_each}</td>" \ "<td class='c'>#{_brackets}</td>" \ "<td class='c'>#{_brackets_eq}</td>" \ "<td class='c'>#{_each_pair}</td>" \ "<td>#{super_cls}</td></tr>\n" @ctr += 1 @text << @empty_row if (@ctr % 5 == 0) end |
.done
Inserts data into md template, writes file
153 154 155 156 157 158 159 160 161 162 163 164 165 |
# File 'lib/su_info/sumd_collections.rb', line 153 def self.done() @text << '</tbody>' # add content to md string @text_md.sub!( /<%= collection %>/, @text ) @text_md.sub!(/<%= hdr %>/, SUMD.sumd_generated_by(name, @version)) # write file, show done message box files = [] files << SUMD.sumd_file_write('Collections.md', @text_md) puts "-------------------------------------------------\n" \ "#{name} wrote the following files:\n#{files.join(10.chr)}\n" end |
.find_nested(obj)
Finds all collections in object namespace, reentrant.
Adds the info to file text string @text
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/su_info/sumd_collections.rb', line 96 def self.find_nested(obj) objects = [] isCls = obj.is_a?(Class) # get constants, divide into object & constants obj.constants.each { |c| next if (isCls && obj.superclass.const_defined?(c) ) o = obj.const_get(c) objects << o if o.is_a?(Module) } add_row(obj, isCls) if obj.public_method_defined?(:each) # run child object constants of obj thru this if (objects.length > 0) objects.sort! { |a,b| a.to_s <=> b.to_s } objects.each { |o| find_nested(o) } end end |