#!/usr/bin/env ruby
#
# beautify-ruby - beautifies Ruby code given on STDIN and prints it to STDOUT

print ARGF.read.

  # put space after comma
  gsub(/(\S,)[ \t]*(\S)/, '\1 \2').

  # put space after single colon
  gsub(/(\w+:)[ \t]*([^:])/, '\1 \2').

  # put spaces around operators
  gsub(%r{(\S)[ \t]*([!<>=*&|^%/~+-]*=>?)[ \t]*(\S)}, '\1 \2 \3').

  # strip excess whitespace at end of lines
  gsub(/[ \t]+$/, "")
