File: post-processing.rb

package info (click to toggle)
ruby-amq-protocol 0.9.2-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 392 kB
  • sloc: ruby: 4,212; python: 247; makefile: 2
file content (25 lines) | stat: -rwxr-xr-x 473 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#!/usr/bin/env ruby
# encoding: utf-8

# helpers
def pass; end

# main
buffer = ARGF.inject(String.new) do |buffer, line|
  # line filters
  line.gsub!(/\s*\n$/, "\n")
  line.gsub!("'", '"')
  line.gsub!('u"', '"') if line =~ /^\s*# \[/

  buffer += line
end

# buffer filters
buffer.gsub!(/\n{2,}/m, "\n\n")
pass while buffer.gsub!(/(\n( *)  end)\n{2,}(\2end)/m, "\\1\n\\3")

# Make sure there's only one \n at the end
pass while buffer.chomp!
buffer += "\n"

puts buffer