再開発メモ003

引っ越し

唐突だが、ここを捨ててはてなブログに移行することにした。
記事の引き継ぎはせず完全に仕切りなおすので、MOE3 の再開発メモは3桁どころか3回で終了。我ながらぐうの音も出ない三日坊主ぶり。


まあどうせ向こうでもやること自体は何も変わらないけど、ひとまず書いた分だけ投下したらこっちは放置しま。

Province モデル

スキーマ

  create_table "provinces", force: true do |t|
    t.string   "code"
    t.string   "fullname"
    t.boolean  "supplycenter", default: false
    t.integer  "homepower_id"
    t.string   "port"
    t.string   "type"
    t.datetime "created_at"
    t.datetime "updated_at"
  end


モデル。Province#shortname もさっくり実装。

class Province < ActiveRecord::Base
  belongs_to :homepower, class_name:'Power'

  def shortname
    code.capitalize
  end
end


そして Province の派生クラス群。
Land と Sea は今のところ空っぽ。Coast は港の扱いがあるので #shortname をオーバーライド。

class Land < Province
end
class Sea < Province
end
class Coast < Province
  def shortname
    result = super
    result += "(%s)"%[port.upcase] if port
    result
  end
end


以上を踏まえて seeds.rb も書き直し。
spec_helper.rb をいじってテストの時も読み込ませるので、テストを実行する度にマスタデータが増えないように最初に delete_all している。
ただし id はリセットされないのでテスト環境専用の扱い。開発環境ではおとなしく rake db:reset しとけ。
DB に依存しない id のリセット方法があったら知りたいけどあまり役には立たないか。

## Power
Power.delete_all
a = Power.create symbol:'A', name:'Austria', genitive:'Austrian'
e = Power.create symbol:'E', name:'England', genitive:'English'
f = Power.create symbol:'F', name:'France',  genitive:'French'
g = Power.create symbol:'G', name:'Germany', genitive:'German'
i = Power.create symbol:'I', name:'Italy',   genitive:'Italian'
r = Power.create symbol:'R', name:'Russia',  genitive:'Russian'
t = Power.create symbol:'T', name:'Turky',   genitive:'Turkish'
Power.create symbol:'X', name:'Master'


## Province
Province.delete_all

# Province: Sea
Sea.create code:"adr", fullname:"Adriatic Sea"
Sea.create code:"aeg", fullname:"Aegean Sea"
Sea.create code:"bal", fullname:"Baltic Sea"
Sea.create code:"bar", fullname:"Barents Sea"
Sea.create code:"bla", fullname:"Black Sea"
Sea.create code:"eas", fullname:"Eastern Mediterranean"
Sea.create code:"eng", fullname:"English Channel"
Sea.create code:"bot", fullname:"Gulf of Bothnia"
Sea.create code:"lyo", fullname:"Gulf of Lyon"
Sea.create code:"hel", fullname:"Helgoland Bight"
Sea.create code:"ion", fullname:"Ionian Sea"
Sea.create code:"iri", fullname:"Irish Sea"
Sea.create code:"mao", fullname:"Mid-Atlantic Ocean"
Sea.create code:"nao", fullname:"North Atlantic Ocean"
Sea.create code:"nth", fullname:"North Sea"
Sea.create code:"nwg", fullname:"Norwegian Sea"
Sea.create code:"ska", fullname:"Skagerrak"
Sea.create code:"tys", fullname:"Tyrrhenian Sea"
Sea.create code:"wes", fullname:"Western Mediterranean"

# Province: Land
Land.create code:"boh",                    homepower:a, fullname:"Bohemia"
Land.create code:"bud", supplycenter:true, homepower:a, fullname:"Budapest"
Land.create code:"bur",                    homepower:f, fullname:"Burgundy"
Land.create code:"gal",                    homepower:a, fullname:"Galicia"
Land.create code:"mos", supplycenter:true, homepower:r, fullname:"Moscow"
Land.create code:"mun", supplycenter:true, homepower:g, fullname:"Munich"
Land.create code:"par", supplycenter:true, homepower:f, fullname:"Paris"
Land.create code:"ruh",                    homepower:g, fullname:"Ruhr"
Land.create code:"ser", supplycenter:true,              fullname:"Serbia"
Land.create code:"sil",                    homepower:g, fullname:"Silesia"
Land.create code:"tyr",                    homepower:a, fullname:"Tyrolia"
Land.create code:"ukr",                    homepower:r, fullname:"Ukraine"
Land.create code:"vie", supplycenter:true, homepower:a, fullname:"Vienna"
Land.create code:"war", supplycenter:true, homepower:r, fullname:"Warsaw"

# Province: Coast
Coast.create code:"alb",                                 fullname:"Albania"
Coast.create code:"ank", supplycenter:true, homepower:t, fullname:"Ankara"
Coast.create code:"apu",                    homepower:i, fullname:"Apulia"
Coast.create code:"arm",                    homepower:t, fullname:"Armenia"
Coast.create code:"bel", supplycenter:true,              fullname:"Belgium"
Coast.create code:"ber", supplycenter:true, homepower:g, fullname:"Berlin"
Coast.create code:"bre", supplycenter:true, homepower:f, fullname:"Brest"
Coast.create code:"bul", supplycenter:true,              fullname:"Bulgaria"
bul = Coast.last
bulec = bul.dup; bulec.port = 'ec'; bulec.save!
bulsc = bul.dup; bulsc.port = 'sc'; bulsc.save!
Coast.create code:"cly",                    homepower:e, fullname:"Clyde"
Coast.create code:"con", supplycenter:true, homepower:t, fullname:"Constantinople"
Coast.create code:"den", supplycenter:true,              fullname:"Denmark"
Coast.create code:"edi", supplycenter:true, homepower:e, fullname:"Edinburgh"
Coast.create code:"fin",                    homepower:r, fullname:"Finland"
Coast.create code:"gas",                    homepower:f, fullname:"Gascony"
Coast.create code:"gre", supplycenter:true,              fullname:"Greece"
Coast.create code:"hol", supplycenter:true,              fullname:"Holland"
Coast.create code:"kie", supplycenter:true, homepower:g, fullname:"Kiel"
Coast.create code:"lon", supplycenter:true, homepower:e, fullname:"London"
Coast.create code:"lvn",                    homepower:r, fullname:"Livonia"
Coast.create code:"lvp", supplycenter:true, homepower:e, fullname:"Liverpool"
Coast.create code:"mar", supplycenter:true, homepower:f, fullname:"Marseilles"
Coast.create code:"naf",                                 fullname:"North Africa"
Coast.create code:"nap", supplycenter:true, homepower:i, fullname:"Naples"
Coast.create code:"nwy", supplycenter:true,              fullname:"Norway"
Coast.create code:"pic",                    homepower:f, fullname:"Picardy"
Coast.create code:"pie",                    homepower:i, fullname:"Piedmont"
Coast.create code:"por", supplycenter:true,              fullname:"Portugal"
Coast.create code:"pru",                    homepower:g, fullname:"Prussia"
Coast.create code:"rom", supplycenter:true, homepower:i, fullname:"Rome"
Coast.create code:"rum", supplycenter:true,              fullname:"Rumania"
Coast.create code:"sev", supplycenter:true, homepower:r, fullname:"Sevastopol"
Coast.create code:"smy", supplycenter:true, homepower:t, fullname:"Smyrna"
Coast.create code:"spa", supplycenter:true,              fullname:"Spain"
spa = Coast.last
spanc = spa.dup; spanc.port = 'nc'; spanc.save!
spasc = spa.dup; spasc.port = 'sc'; spasc.save!
Coast.create code:"stp", supplycenter:true, homepower:r, fullname:"St. Petersburg"
stp = Coast.last
stpnc = stp.dup; stpnc.port = 'nc'; stpnc.save!
stpsc = stp.dup; stpsc.port = 'sc'; stpsc.save!
Coast.create code:"swe", supplycenter:true,              fullname:"Sweden"
Coast.create code:"syr",                                 fullname:"Syria"
Coast.create code:"tri", supplycenter:true, homepower:a, fullname:"Trieste"
Coast.create code:"tun", supplycenter:true,              fullname:"Tunis"
Coast.create code:"tus",                    homepower:i, fullname:"Tuscany"
Coast.create code:"ven", supplycenter:true, homepower:i, fullname:"Venice"
Coast.create code:"wal",                    homepower:e, fullname:"Wales"
Coast.create code:"yor",                    homepower:e, fullname:"Yorkshire"


うむ。相変わらずシングルクォートとダブルクォートの混在が見苦しい。後でダブルに統一しておこう。


次は何をするか。
Province を作った流れで「Adjacency(隣接情報)」に手を出すのもいいけど、これが必要になるのはずっと後のはず。なのでやっぱり「Order」かな。