Class: YARD::Parser::RSpecParser

Inherits:
Base
  • Object
show all
Defined in:
lib/rspec/illustrate/yard.rb

Overview

Parses the output from the RSpec::Illustrate::YARD formatter (which is valid html) and inserts the nodes into the corresponding CodeObject.

Instance Method Summary (collapse)

Constructor Details

- (RSpecParser) initialize(source, filename)

Returns a new instance of RSpecParser



18
19
20
# File 'lib/rspec/illustrate/yard.rb', line 18

def initialize(source, filename)
  @source = source
end

Instance Method Details

- (Object) enumerator

See Also:

  • Base#enumerator


47
48
49
# File 'lib/rspec/illustrate/yard.rb', line 47

def enumerator
  nil
end

- (Object) parse

See Also:

  • Base#parse


23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/rspec/illustrate/yard.rb', line 23

def parse
  document = REXML::Document.new(@source)
  document.elements.each("html/body/div") {|element|
    if (path = element.attributes["id"].sub(/^rspec_/, '')) then
      if codeobject = YARD::Registry.at(path) then
        # only grab the <div> that contains the child elements, and omit
        # caption since we already gave a Specification header.
        examples = element.elements["div[@class='rspec_example_group_children']"]
        (codeobject[:rspec] ||= []).concat(examples.to_a)
      else
        log.warn "Could not find code object for #{path}, adding it to top level namespace."
        (YARD::Registry.root[:rspec] ||= []).concat(element.to_a)
      end
    end
  }
  self
end

- (Object) tokenize

See Also:

  • Base#tokenize


42
43
44
# File 'lib/rspec/illustrate/yard.rb', line 42

def tokenize
  []
end