class Loincloth::BlockParser
Constants
- BLOCK_SEPARATOR
Public Class Methods
new(stream)
click to toggle source
# File lib/loincloth/block_parser.rb, line 3 def initialize(stream) @stream = stream end
Public Instance Methods
each_block(&action)
click to toggle source
# File lib/loincloth/block_parser.rb, line 6 def each_block(&action) buffer = [] @stream.each{ |line| if is_block_separator(line) do_action(action, buffer) buffer = [] else buffer << line.chomp end } do_action(action, buffer) end
Private Instance Methods
do_action(action, buffer)
click to toggle source
# File lib/loincloth/block_parser.rb, line 27 def do_action(action, buffer) action.call(Block.new(buffer.join("\n"))) unless buffer.empty? end
is_block_separator(line)
click to toggle source
# File lib/loincloth/block_parser.rb, line 23 def is_block_separator(line) line =~ BLOCK_SEPARATOR end