Skip to content

Commit

Permalink
More robust Docstring summary
Browse files Browse the repository at this point in the history
  • Loading branch information
tlewin committed Dec 29, 2014
1 parent 41d2a36 commit ee3e2a9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
15 changes: 10 additions & 5 deletions lib/yard/docstring.rb
Expand Up @@ -172,15 +172,20 @@ def summary
resolve_reference
return @summary if @summary
stripped = self.gsub(/<.+?>/m, '').gsub(/[\r\n](?![\r\n])/, ' ').strip
open_parens = ['{', '(', '[']
close_parens = ['}', ')', ']']
num_parens = 0
idx = length.times do |index|
case stripped[index, 1]
when ".", "\r", "\n"
when "."
next_char = stripped[index + 1, 1].to_s
if num_parens == 0 && next_char =~ /^\s*$/
break index - 1
break index - 1 if num_parens <= 0 && next_char =~ /^\s*$/
when "\r", "\n"
next_char = stripped[index + 1, 1].to_s
if next_char =~ /^\s*$/
if stripped[index - 1, 1] == '.'
break index - 2
else
break index - 1
end
end
when "{", "(", "["
num_parens += 1
Expand Down
7 changes: 7 additions & 0 deletions spec/docstring_spec.rb
Expand Up @@ -113,6 +113,13 @@
Docstring.new("hello... me").summary.should == "hello..."
Docstring.new("hello.").summary.should == "hello."
end

it "should return summary if there is a newline and parentheses count doesn't match" do
Docstring.new("Happy method call :-)\n\nCall any time.").summary.should == "Happy method call :-)."
Docstring.new("Sad method call :-(\n\nCall any time.").summary.should == "Sad method call :-(."
Docstring.new("Hello (World. Forget to close.\n\nNew text").summary.should == "Hello (World. Forget to close."
Docstring.new("Hello (World. Forget to close\n\nNew text").summary.should == "Hello (World. Forget to close."
end
end

describe '#ref_tags' do
Expand Down

0 comments on commit ee3e2a9

Please sign in to comment.