class Zapata::Core::Writer

Public Class Methods

new(filename) click to toggle source
# File lib/zapata/core/writer.rb, line 6
def initialize(filename)
  @filename = filename
  @padding = 0
  clean
end

Public Instance Methods

append_line(line = '') click to toggle source
# File lib/zapata/core/writer.rb, line 18
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
clean() click to toggle source
# File lib/zapata/core/writer.rb, line 12
def clean
  file = File.open(@filename, 'w')
  file.write('')
  file.close
end
word_exists?(string, word) click to toggle source
# File lib/zapata/core/writer.rb, line 30
def word_exists?(string, word)
  !!/\b(?:#{word})\b/.match(string)
end