helpers.rb
# Splits the given data into sections where each section is either
# a string paragraph, or a list of bullet points. The near_items
# arg is the other items in the same list that the data arg is from
# and are used to treat the data like bullet points if most of the
# other items are bullet points.
Splits the given data into sections where each section is either
a string paragraph, or a list of bullet points. The near_items
arg is the other items in the same list that the data arg is from
and are used to treat the data like bullet points if most of the
other items are bullet points.
Splits the given data into sections where each section is either a string paragraph or a list of bullet points . The near_items arg is the other items in the same list that the data arg is from and are used to treat the data like bullet points if most of the other items are bullet points .
def sections(data, near_items)
    bullets = /^(\*|-|–|—|·|•)/
    most_near_are_points = most_near_are_points? near_items
    (data || "").split("\n\n").map {|section|
      points = section.split("\n").map{ |point| point.strip }
      is_points = points.reject {|point| point =~ bullets}.size == 0
      if is_points || most_near_are_points
        points.map {|point| point.gsub(bullets, "").strip}
      else
        section.gsub("\n", "<br>")
      end
    }
  end
def sections ( data , near_items ) bullets = / ^( \* |-|–|—|·|•)/ most_near_are_points = most_near_are_points? near_items ( data || "" ) . split ( "\n\n" ) . map { | section | points = section . split ( "\n" ) . map { | point | point . strip } is_points = points . reject { | point | point =~ bullets } . size == 0 if is_points || most_near_are_points points . map { | point | point . gsub ( bullets , "" ) . strip } else section . gsub ( "\n" , "<br>" ) end } end
Splits the given data into sections where each section is either
a string paragraph, or a list of bullet points.
Splits the given data into sections where each section is either a string paragraph or a list of bullet points .
# The section is bullet points if all the lines start with a bullet. # Bullet points - remove the bullet from each point. # Just a paragraph of text.
data
<not_specific>
near_items
<not_specific>