Class: Rumld::RDocInspector
- Inherits:
-
Object
- Object
- Rumld::RDocInspector
- Defined in:
- lib/rumld/rdoc_inspector.rb
Constant Summary collapse
- XPATH_TO_METHOD_SECTION_HEADER =
'#methods > h3'
- METHOD_HEADING_TABLE =
{'Public Class methods' => :public_class, 'Public Instance methods' => :public_instance, 'Protected Instance methods' => :protected_instance, 'Protected Class methods' => :protected_class }
Instance Attribute Summary collapse
-
#constant_name ⇒ Object
readonly
Returns the value of attribute constant_name.
-
#node ⇒ Object
readonly
Returns the value of attribute node.
Class Method Summary collapse
Instance Method Summary collapse
- #all_included_modules ⇒ Object
- #doc ⇒ Object
- #doc_file_for ⇒ Object
- #doc_is_for_module? ⇒ Boolean
- #find_methods_in_section(method_section) ⇒ Object
-
#initialize(node, constant_name) ⇒ RDocInspector
constructor
A new instance of RDocInspector.
-
#methods_by_section ⇒ Object
Given an RDoc class.html file, kick back a hash of methods.
Constructor Details
#initialize(node, constant_name) ⇒ RDocInspector
Returns a new instance of RDocInspector.
16 17 18 19 |
# File 'lib/rumld/rdoc_inspector.rb', line 16 def initialize(node, constant_name) @node = node @constant_name = constant_name end |
Instance Attribute Details
#constant_name ⇒ Object (readonly)
Returns the value of attribute constant_name.
15 16 17 |
# File 'lib/rumld/rdoc_inspector.rb', line 15 def constant_name @constant_name end |
#node ⇒ Object (readonly)
Returns the value of attribute node.
15 16 17 |
# File 'lib/rumld/rdoc_inspector.rb', line 15 def node @node end |
Class Method Details
.doc_file_for(doc_dir, constant_name) ⇒ Object
4 5 6 |
# File 'lib/rumld/rdoc_inspector.rb', line 4 def doc_file_for(doc_dir, constant_name) File.join(doc_dir, 'classes', "#{constant_name.gsub('::', '/')}.html") end |
Instance Method Details
#all_included_modules ⇒ Object
29 30 31 |
# File 'lib/rumld/rdoc_inspector.rb', line 29 def all_included_modules self.doc.search('#includes #includes-list .include-name').collect{|n| n.inner_text} end |
#doc ⇒ Object
21 22 23 |
# File 'lib/rumld/rdoc_inspector.rb', line 21 def doc @doc ||= open( doc_file_for ) {|f| Hpricot(f)} end |
#doc_file_for ⇒ Object
25 26 27 |
# File 'lib/rumld/rdoc_inspector.rb', line 25 def doc_file_for self.class.doc_file_for(node.doc_dir, constant_name) end |
#doc_is_for_module? ⇒ Boolean
33 34 35 36 37 38 |
# File 'lib/rumld/rdoc_inspector.rb', line 33 def doc_is_for_module? if @doc_is_for_module.nil? @doc_is_for_module = (self.doc.search('#classHeader table.header-table tr td strong')[0].inner_html == 'Module') end @doc_is_for_module end |
#find_methods_in_section(method_section) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/rumld/rdoc_inspector.rb', line 53 def find_methods_in_section(method_section) collector = [] # Oh why did method_section lose the following method? child = method_section.next_sibling while child && !child.css_path.include?(XPATH_TO_METHOD_SECTION_HEADER) # We got to a new section, so drop out of this silly non-sense break if child.css_path.include?(XPATH_TO_METHOD_SECTION_HEADER) (child/'.method-heading a').each do |signature| if string = signature.inner_text.strip.chomp collector << string end end child = child.next_sibling end collector.sort! end |
#methods_by_section ⇒ Object
Given an RDoc class.html file, kick back a hash of methods
41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/rumld/rdoc_inspector.rb', line 41 def methods_by_section unless @methods_by_section @methods_by_section = {} (self.doc/XPATH_TO_METHOD_SECTION_HEADER).each do |method_section| if collector_key = METHOD_HEADING_TABLE[method_section.inner_html] @methods_by_section[collector_key] = find_methods_in_section(method_section) end end end @methods_by_section end |