ruby on rails - Join country calling codes to country table list -
i creating rails project requires country table. include country calling codes them. found in creating country table github , looks this:
class createcountries < activerecord::migration def change create_table :countries |t| t.string :name t.string :printable_name t.string :iso2, :size => 2 t.string :iso3, :size => 3 t.integer :numcode t.timestamps end end country.reset_column_information country.create(:iso2 => 'af', :name => 'afghanistan', :printable_name => 'afghanistan', :iso3 => 'afg', :numcode => '004') country.create(:iso2 => 'al', :name => 'albania', :printable_name => 'albania', :iso3 => 'alb', :numcode => '008') country.create(:iso2 => 'dz', :name => 'algeria', :printable_name => 'algeria', :iso3 => 'dza', :numcode => '012')
and i've found list of country calling codes , managed put them in spreadsheet:
afghanistan 93 albania 355 algeria 213
what i'd fast way join calling code above list looks this:
country.create(:iso2 => 'af', :name => 'afghanistan', :printable_name => 'afghanistan', :iso3 => 'afg', :numcode => '004' :call_code => 93)
any fast solution achieve using excel or openoffice spreadsheet or mysql? long dont have key in manually.
- copy
country.create
lines of code excel, starting in a1. - copy list of codes excel , if necessary split 2 columns (eg text columns).
- name result (say
carray
). - in b1 put:
=find("printable_name => '",a1)+19
. in c1 put:
=substitute(a1,")"," :call_code => "&vlookup(mid(a1,b1,find("'",a1,b1)-b1),carray,2,0)&")")
copy b1:c1 down suit.
- copy of columnc in code suitable.
carray
need not in same sheet.
Comments
Post a Comment