「分かりやすい平面直角座標系」の Ruby 実装

市区町村コードから平面直角座標系の系の番号や EPSG コードを得る Ruby コードです。
誰かが公開しておくと多くの人(公開した人も含め)の手間が減りそうなので、ここに置いておきます。cc2epsg.rb という名前にしたいと思います。cc は city code の意味です。
コード本文にも書きましたが無保証である点よろしくお願いします。北海道と鹿児島県と沖縄県で else で逃げているところがあるので、特にそのあたりにバグが入り込んでいる余地があるかも知れません。

# cc2espg.rb: Ruby implementation of 
# http://vldb.gsi.go.jp/sokuchi/patchjgd/download/Help/jpc/jpc.htm#sansho

# Usage of the works is permitted provided that this insturment is retained
# with the works, so that any entity that uses the works is notified of this
# instrument.
# 
# DISCLAIMER: THE WORKS ARE WITHOUT WARRANTY.

CC2EPSG_VERSION = 20091119

def cc2epsg(city_code)
  cc2kei(city_code) + 2442
end

def cc2kei(city_code)
  case city_code.to_i / 1000
  when 1
    case city_code.to_i
    when 1203, 1202, 1233, 1236, 1575, 1571, 1584, 1514, 1362, 1363, 1364, 1371, 1367, 1370, 1203, 1391, 1392, 1393, 1394, 1395, 1396, 1397, 1398, 1399, 1400, 1401, 1402, 1403, 1404, 1405, 1406, 1407, 1408, 1409, 1202, 1331, 1332, 1333, 1334, 1236, 1337, 1343, 1345, 1346, 1347
      11
    when 1208, 1207, 1206, 1211, 1223, 1691, 1692, 1693, 1694, 1695, 1696, 1697, 1698, 1699, 1700, 1661, 1662, 1663, 1664, 1665, 1667, 1668, 1219, 1564, 1543, 1544, 1545, 1546, 1547, 1549, 1550, 1552, 1631, 1632, 1633, 1634, 1635, 1636, 1637, 1638, 1639, 1641, 1642, 1643, 1644, 1645, 1646, 1647, 1648, 1649
      13
    else #
      12
    end
  when 2
    10
  when 3
    10
  when 4
    10
  when 5
    10
  when 6
    10
  when 7
    9
  when 8
    9
  when 9
    9
  when 10
    9
  when 11
    9
  when 12
    9
  when 13
    case city_code.to_i
    when 13421
      raise "Ogasawara-mura has multiple keis and not supported in this version."
    else 
      9
    end
  when 14
    9
  when 15
    8
  when 16
    7
  when 17
    7
  when 18
    6
  when 19
    8
  when 20
    8
  when 21
    7
  when 22
    8
  when 23
    7
  when 24
    6
  when 25
    6
  when 26
    6
  when 27
    6
  when 28
    5
  when 29
    6
  when 30
    6
  when 31
    5
  when 32
    3
  when 33
    5
  when 34
    3
  when 35
    3
  when 36
    4
  when 37
    4
  when 38
    4
  when 39
    4
  when 40
    2
  when 41
    2
  when 42
    1
  when 43
    2
  when 44
    2
  when 45
    2
  when 46
    case city_code.to_i
    when 46220
      raise "Minami-satsuma-shi has multiple keis."
    when 46222, 46304, 46220, 46215, 46523, 46524, 46525, 46527, 46529, 46530, 46531, 46532, 46533, 46534, 46535, 46303
      1
    else #
      2
    end
  when 47
    case city_code.to_i
    when 47357, 47358
      17
    when 47214, 47375, 47207, 47381, 47382
      16
    else #
      15
    end
  else
    raise "Cannot determine kei for city code #{city_code}."
  end
end