#!/usr/bin/env ruby # -*- coding: utf-8 -*- require 'json' myname = File.basename($0) if !ARGV[0] then STDERR.puts "uMap inline img {{img-URL}} notation to SakataMap schema" STDERR.puts "Usage: #{myname} [Options] geojsonFile(s)" STDERR.puts "" STDERR.puts "The `orig-skt.geojson' file overwritten from `orig.geojson'." end for f in ARGV begin j = JSON.load(open(f){|j|j.read}) next unless j["features"].length rescue STDERR.puts "Failed to load [#{f}], skipped" next end skt = File.basename(f, ".geojson") + "-skt.geojson" for feat in j["features"] next unless feat["type"] == "Feature" if (prop = feat["properties"]) then if (desc = prop["description"]) then images = [] while /{{(\S+)}}/ =~ desc images << $1 desc.sub!(/{{\S+?}}/, "") desc.chomp! end if images[0] then prop["画像"] = images.join(";") end end end end open(skt, "w") {|n| n.write(JSON.pretty_generate(j))} and STDERR.puts "Output to [#{skt}]" end