Martin DeMello
3/25/2008 9:15:00 PM
On Tue, Mar 25, 2008 at 2:02 PM, Martin DeMello <martindemello@gmail.com> wrote:
> Given:
> an outline list, with each line indented by a series of tabs
> a list of bullets (assume a circular list, for simplicity)
>
> Write a function that replaces every tab with two spaces, except for
> the last one, which is replaced by a bullet.
Code is worth a thousand descriptions:
#!/usr/bin/ruby
file = ARGV[0]
MARKERS = "*-ox".split(//)
def bullet(n)
MARKERS[n % MARKERS.length]
end
IO.foreach(file) {|line|
a = line.gsub(/^\t+/, "")
n = line.length - a.length - 1
replace = n == -1 ? "" : " "*(n)+ bullet(n) + " "
out = line.gsub(/^\t+/, replace)
puts out
}
martin