Class: Propolize::ListChunk

Inherits:
BlankTerminatedChunk show all
Defined in:
lib/propolize.rb

Overview

A list chunk represents a list of list items (recognised because the first line starts with “* ”)

Instance Attribute Summary

Attributes inherited from LinesChunk

#lines

Instance Method Summary collapse

Methods inherited from BlankTerminatedChunk

#critiqueValue, #isTerminatedBy?

Methods inherited from LinesChunk

#addLine, #initialize, #postProcess

Constructor Details

This class inherits a constructor from Propolize::LinesChunk

Instance Method Details

#addItemToList(itemList, currentItemLines) ⇒ Object



856
857
858
# File 'lib/propolize.rb', line 856

def addItemToList(itemList, currentItemLines)
  itemList.addItem(ListItem.new(currentItemLines.join("\n")))
end

#getDocumentComponentObject



860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
# File 'lib/propolize.rb', line 860

def getDocumentComponent
  itemList = ItemList.new(:isCritique => @isCritique)
  currentItemLines = nil
  # loop over lines
  for line in lines do
    itemStartMatch = line.match(/^\*\s+(.*)$/) # if a line starts with "* ", 
    if itemStartMatch  # we have found the start of a new item
      if currentItemLines != nil
        addItemToList(itemList, currentItemLines) # save the previous list item if any
      end
      currentItemLines = [itemStartMatch[1]] # start the new list of lines for this item
    else
      currentItemLines.push(line.strip) # add this line to the existing list of lines for the current list item
    end
  end
  if currentItemLines != nil
    addItemToList(itemList, currentItemLines) # save any final list item not yet saved
  end
  return itemList
end

#to_sObject



852
853
854
# File 'lib/propolize.rb', line 852

def to_s
  return "ListChunk: #{critiqueValue}#{lines.inspect}"
end