Sha256: ed8e4f0ea241f9c20c9dcd8827d86664fa030c025d433795dace4229aeff65c6

Contents?: true

Size: 702 Bytes

Versions: 1

Compression:

Stored size: 702 Bytes

Contents

require "fixbraces/version"
require "tempfile"

module Fixbraces
  def Fixbraces.fixbraces(text)
    # Move the opening brace to the same line as the opening clause
    partial_result = text.gsub(/\n[ \t]*\{[ \t]*$/, " {")

    # If there are a pair of braces on their own line move them both up to the
    # same line as the opening line
    partial_result.gsub(/\n[\s]*\{\}[\s]*$/, " {}")
  end

  def Fixbraces.process_file(file)
    temp_file = Tempfile.new "fixbraces"
    File.open(file, "r") do |f|
      contents = f.read
      new_contents = fixbraces contents
      temp_file.write new_contents
    end
    temp_file.close
    FileUtils.cp temp_file.path, file
    temp_file.unlink
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
fixbraces-0.9.0 lib/fixbraces.rb