lib/dead_end/clean_document.rb
def join_groups(groups)
      groups.each do |lines|
        line = lines.first

        # Handle the case of multiple groups in a a row
        # if one is already replaced, move on
        next if @document[line.index].empty?

        # Join group into the first line
        @document[line.index] = CodeLine.new(
          lex: lines.map(&:lex).flatten,
          line: lines.join,
          index: line.index
        )

        # Hide the rest of the lines
        lines[1..-1].each do |line|
          # The above lines already have newlines in them, if add more
          # then there will be double newline, use an empty line instead
          @document[line.index] = CodeLine.new(line: "", index: line.index, lex: [])
        end
      end
      self
    end
# Helper method for joining "groups" of lines
#
# Input is expected to be type Array<Array<CodeLine>>
#
# The outer array holds the various "groups" while the
# inner array holds code lines.
#
# All code lines are "joined" into the first line in
# their group.
#
# To preserve document size, empty lines are placed
# in the place of the lines that were "joined"
Helper method for joining "groups" of lines
Input is expected to be type Array>

The outer array holds the various "groups" while the
inner array holds code lines.

All code lines are "joined" into the first line in
their group.

To preserve document size, empty lines are placed
in the place of the lines that were "joined"
Helper method for joining " groups " of lines Input is expected to be type Array > The outer array holds the various " groups " while the inner array holds code lines . All code lines are " joined " into the first line in their group . To preserve document size empty lines are placed in the place of the lines that were " joined "
def join_groups(groups)
      groups.each do |lines|
        line = lines.first
        next if @document[line.index].empty?
        @document[line.index] = CodeLine.new(
          lex: lines.map(&:lex).flatten,
          line: lines.join,
          index: line.index
        )
        lines[1..-1].each do |line|
          @document[line.index] = CodeLine.new(line: "", index: line.index, lex: [])
        end
      end
      self
    end
def join_groups ( groups ) groups . each do | lines | line = lines . first next if @document [ line . index ] . empty? @document [ line . index ] = CodeLine . new ( lex : lines . map ( & :lex ) . flatten , line : lines . join , index : line . index ) lines [ 1 .. - 1 ] . each do | line | @document [ line . index ] = CodeLine . new ( line : "" , index : line . index , lex : [ ] ) end end self end
Helper method for joining "groups" of lines
Input is expected to be type Array<Array<CodeLine>>
Helper method for joining " groups " of lines Input is expected to be type Array<Array<CodeLine >>
# Handle the case of multiple groups in a a row # if one is already replaced, move on # Join group into the first line # Hide the rest of the lines # The above lines already have newlines in them, if add more # then there will be double newline, use an empty line instead
groups