Sha256: 27010370b489fd7e832c35388a54d27bcee185fa959700d634396e036b123098
Contents?: true
Size: 737 Bytes
Versions: 1
Compression:
Stored size: 737 Bytes
Contents
# frozen_string_literal: true 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
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
zapata-1.0.0 | lib/zapata/core/writer.rb |