Class: RSpec::Apib::CommentsParser

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec/apib/comments_parser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(example) ⇒ CommentsParser

Returns a new instance of CommentsParser.



6
7
8
# File 'lib/rspec/apib/comments_parser.rb', line 6

def initialize(example)
  @example = example
end

Instance Attribute Details

#exampleObject (readonly)

Returns the value of attribute example.



4
5
6
# File 'lib/rspec/apib/comments_parser.rb', line 4

def example
  @example
end

Instance Method Details

#description(namespace = nil) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/rspec/apib/comments_parser.rb', line 28

def description(namespace = nil)
  matcher = start_matcher(namespace)
  comment = full_comment()
  in_comment = false
  return nil if comment.blank?

  comment.select do |elem|
    if elem == matcher
      in_comment = true
    elsif elem.match?(/\A---($|[^-])/)
      in_comment = false
    end

    in_comment && elem != matcher
  end.join("\n")
end

#full_commentObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/rspec/apib/comments_parser.rb', line 10

def full_comment
  line = example.[:line_number]
  return if line.nil? || line <= 0

  lines = read_example_file
  return if lines.count < line

  i = line -2
  result = []

  while (i >= 0 && match = lines[i].match(/\A\s*#\s(.*)/)) do
    result.unshift(match[1])
    i -= 1
  end

  result
end