#!/usr/bin/env ruby
# $Id: imagemap2meta.rb,v 1.1 2003/01/22 14:37:22 danbri Exp $
# Ruby script to convert Gimp imagemap (HTML Tidy'd) into SVG and/or RDF
#
#
# Notes: this doesn't work yet. Still figuring out how to replace my favourite perlisms w/ Ruby code

if ARGV.length > 0
  file=ARGV[0]
  else
  puts "Usage: $0 <imagemapfile> \n"
  raise "No filename supplied"
end

##  called with each row of properties
#
def getArea (text, areas)
  remainder = text  
  puts "\n\ngetArea called with: #{text} \n\n"
  if text =~ /SHAPE="([^"]+?)"\s+COORDS="([^"]+?)"\s+ALT="([^"]+?)"\s+HREF="([^"]+?)"(.*)/i   
    meta={}
    meta['shape']=$1
    meta['coords']=$2
    meta['alt']=$3
    meta['href']=$4
    remainder = $5
    puts "\nLeft: +++ #{remainder} --- \n\n"
    puts "Area: #{meta.inspect}\n"
    areas.push meta
  end
  return remainder
end

##
#
map = `cat #{file}`
map.gsub!(/\n/,"")

areas=[]

more=true

while more
  map =~ /<AREA([^>]+?)>/mi
  puts "sending  [[[ #{$1} ]]] to getArea" 
  map = getArea ($1,areas)
  if ! map =~ m/AREA/ 
    more=false
  end
end



puts "Leftover: "+map 

puts "Results: "+ areas.inspect

