Class: Rumld::RDocInspector

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

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_nameObject (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

#nodeObject (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_modulesObject



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

#docObject



21
22
23
# File 'lib/rumld/rdoc_inspector.rb', line 21

def doc
  @doc ||= open( doc_file_for ) {|f| Hpricot(f)}
end

#doc_file_forObject



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

Returns:

  • (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_sectionObject

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