Class: RSpec::Apib::CommentsParser
- Inherits:
-
Object
- Object
- RSpec::Apib::CommentsParser
- Defined in:
- lib/rspec/apib/comments_parser.rb
Instance Attribute Summary collapse
-
#example ⇒ Object
readonly
Returns the value of attribute example.
Instance Method Summary collapse
- #description(namespace = nil) ⇒ Object
- #full_comment ⇒ Object
-
#initialize(example) ⇒ CommentsParser
constructor
A new instance of CommentsParser.
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
#example ⇒ Object (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_comment ⇒ Object
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 |