lib/cri/string_formatter.rb
# Extracts individual paragraphs (separated by two newlines).
#
# @param [String] str The string to format
#
# @return [Array<String>] A list of paragraphs in the string
Extracts individual paragraphs (separated by two newlines).
Extracts individual paragraphs ( separated by two newlines ) .
def to_paragraphs(str)
      lines = str.scan(/([^\n]+\n|[^\n]*$)/).map { |l| l[0].strip }
      paragraphs = [[]]
      lines.each do |line|
        if line.empty?
          paragraphs << []
        else
          paragraphs.last << line
        end
      end
      paragraphs.reject(&:empty?).map { |p| p.join(' ') }
    end
def to_paragraphs ( str ) lines = str . scan ( / ([^ \n ]+ \n |[^ \n ]*$) / ) . map { | l | l [ 0 ] . strip } paragraphs = [ [ ] ] lines . each do | line | if line . empty? paragraphs << [ ] else paragraphs . last << line end end paragraphs . reject ( & :empty? ) . map { | p | p . join ( ' ' ) } end
Extracts individual paragraphs (separated by two newlines).
Extracts individual paragraphs ( separated by two newlines ) .
A list of paragraphs in the string
A list of paragraphs in the string
Array<String>
str
<not_specific>
<not_specific>
str The string to format
str The string to format