Sha256: 9366b65ddb500de49524d8d4b3e37f946eaf48afd2cada0f814a8fe031306be8
Contents?: true
Size: 1.27 KB
Versions: 2
Compression:
Stored size: 1.27 KB
Contents
module Faml class LineParser attr_reader :filename, :lineno def initialize(filename, template_str) @filename = filename @lines = template_str.each_line.map { |line| line.chomp.rstrip } @lineno = 0 end def next_line line = move_next if is_multiline?(line) next_multiline(line) else line end end def has_next? @lineno < @lines.size end private MULTILINE_SUFFIX = ' |' # Regex to check for blocks with spaces around arguments. Not to be confused # with multiline script. # For example: # foo.each do | bar | # = bar # BLOCK_WITH_SPACES = /do\s*\|\s*[^\|]*\s+\|\z/o def is_multiline?(line) line = line.lstrip line.end_with?(MULTILINE_SUFFIX) && line !~ BLOCK_WITH_SPACES end def move_next @lines[@lineno].tap do @lineno += 1 end end def move_back @lineno -= 1 end def next_multiline(line) buf = [line[0, line.size-1]] while @lineno < @lines.size line = move_next if is_multiline?(line) line = line[0, line.size-1] buf << line.lstrip else move_back break end end buf.join end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
faml-0.2.8 | lib/faml/line_parser.rb |
faml-0.2.7 | lib/faml/line_parser.rb |