Sha256: 3d81a67999cd4ceceb73ba24de3126680a92d289e90b6757e699b5840b83e619
Contents?: true
Size: 706 Bytes
Versions: 10
Compression:
Stored size: 706 Bytes
Contents
module Zapata module Core class Writer def initialize(filename) @filename = filename @padding = 0 clean end def clean file = File.open(@filename, 'w') file.write('') file.close end def append_line(line = '') @padding -= 1 if word_exists?(line, 'end') padding_to_use = @padding padding_to_use = 0 if line.empty? file = File.open(@filename, 'ab+') file.puts("#{' ' * padding_to_use}#{line}") file.close @padding += 1 if word_exists?(line, 'do') end def word_exists?(string, word) !!/\b(?:#{word})\b/.match(string) end end end end
Version data entries
10 entries across 10 versions & 1 rubygems