Skip to content

Commit d3e62fd

Browse files
committed
Extract repeated regexp as a constant
1 parent c23bf63 commit d3e62fd

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

lib/rdoc/generator/darkfish.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -700,6 +700,8 @@ def template_for file, page = true, klass = ERB
700700
template
701701
end
702702

703+
ParagraphExcerptRegexp = /[A-Z][^\.:\/]+\./
704+
703705
# Returns an excerpt of the comment for usage in meta description tags
704706
def excerpt(comment)
705707
text = case comment
@@ -711,11 +713,11 @@ def excerpt(comment)
711713

712714
# Match from a capital letter to the first period, discarding any links, so
713715
# that we don't end up matching badges in the README
714-
first_paragraph_match = text.match(/[A-Z][^\.:\/]+\./)
716+
first_paragraph_match = text.match(ParagraphExcerptRegexp)
715717
return text[0...150].gsub(/\n/, " ").squeeze(" ") unless first_paragraph_match
716718

717719
extracted_text = first_paragraph_match[0]
718-
second_paragraph = first_paragraph_match.post_match.match(/[A-Z][^\.:\/]+\./)
720+
second_paragraph = first_paragraph_match.post_match.match(ParagraphExcerptRegexp)
719721
extracted_text << " " << second_paragraph[0] if second_paragraph
720722

721723
extracted_text[0...150].gsub(/\n/, " ").squeeze(" ")

0 commit comments

Comments
 (0)