nunojob:~ dscape/08$ echo The Black Sheep

First download the flags from famfamfam into a folder called flags (pngs only,
no subfolders!).

Now in the bash:

cd flags
wget http://www.iso.org/iso/iso3166_en_code_lists.txt
ls > file.txt
irb

Now your on the interactive ruby shell (irb).

# If you want to use this as a script just copy
# the bash lines and put them as
# system ‘cd flags’
# system ‘wget …’ and so on

# We start treating the output from the ls
# open the ls output
f = File.new ‘file.txt’
# place the file in lines
lines = f.readlines
# map those who have 2 digits codes
lines = lines.select { |line| line.size == 7 }
# get the 2 digits
lines = lines.map { |line| line[0..1] }
f.close

# Then the iso file
# open the iso file
f = File.new ‘iso3166_en_code_lists.txt’
# get rid of the notes
f.readline
# place the file in iso
iso = f.readlines
# create a new hash
hashed_iso = {}
# select non empty lines
iso.select { |a| !a.rstrip.empty? }.map do |b|
# remove the whitespaces and split in ‘;’
aux = b.rstrip.split ‘;’
# place info in the hash
hashed_iso[aux[1].downcase] = aux[0].capitalize
end
f.close

# Now we cross information giving more
# importance to what’s in the iso.
iso_famfamfam = hashed_iso.select {
# select those who have flags in famfamfam
|k,v| lines.member? k
}.sort_by {
# sort them by the name the user will see
|pair| pair[1]
}

# Now we create the contents to store in the yaml file
# create the yaml first line
yaml_lines = “hash: \n”
iso_famfamfam.each do |pair|
# for each pair, create the yaml
# representation and put in yaml_lines
yaml_lines < < ' ' + pair[0] + ': ' + pair[1] + "\n" end yaml_lines << "array: ---\n" iso_famfamfam.each do |pair| yaml_lines << '- - ' + pair[0] + "\n - " + pair[1] + "\n" end # put it in a file f = File.new 'flags.yml', 'w' f.write yaml_lines f.close #sample for loading the yaml into ruby f = File.new 'flags.yml' fy = YAML.load f [/sourcecode] Now you have your yaml representation of the flags. Do what you please. Personally I'm going to use the file to load it to Ruby when my Ruby on Rails app starts and use it as part of the registration system in the Open Source Online Testing System.

Comments on: "famfamfam flag iconset yaml representation on ruby" (1)

  1. —
    af: Afghanistan
    al: Albania
    dz: Algeria
    as: American samoa
    ad: Andorra
    ao: Angola
    ai: Anguilla
    ag: Antigua and barbuda
    ar: Argentina
    am: Armenia
    aw: Aruba
    au: Australia
    at: Austria
    az: Azerbaijan
    bs: Bahamas
    bh: Bahrain
    bd: Bangladesh
    bb: Barbados
    by: Belarus
    be: Belgium
    bz: Belize
    bj: Benin
    bm: Bermuda
    bt: Bhutan
    bo: Bolivia
    ba: Bosnia and herzegovina
    bw: Botswana
    bv: Bouvet island
    br: Brazil
    io: British indian ocean territory
    bn: Brunei darussalam
    bg: Bulgaria
    bf: Burkina faso
    bi: Burundi
    kh: Cambodia
    cm: Cameroon
    ca: Canada
    cv: Cape verde
    ky: Cayman islands
    cf: Central african republic
    td: Chad
    cl: Chile
    cn: China
    cx: Christmas island
    cc: Cocos (keeling) islands
    co: Colombia
    km: Comoros
    cg: Congo
    cd: Congo, the democratic republic of the
    ck: Cook islands
    cr: Costa rica
    hr: Croatia
    cu: Cuba
    cy: Cyprus
    cz: Czech republic
    ci: C�te d’ivoire
    dk: Denmark
    dj: Djibouti
    dm: Dominica
    do: Dominican republic
    ec: Ecuador
    eg: Egypt
    sv: El salvador
    gq: Equatorial guinea
    er: Eritrea
    ee: Estonia
    et: Ethiopia
    fk: Falkland islands (malvinas)
    fo: Faroe islands
    fj: Fiji
    fi: Finland
    fr: France
    gf: French guiana
    pf: French polynesia
    tf: French southern territories
    ga: Gabon
    gm: Gambia
    ge: Georgia
    de: Germany
    gh: Ghana
    gi: Gibraltar
    gr: Greece
    gl: Greenland
    gd: Grenada
    gp: Guadeloupe
    gu: Guam
    gt: Guatemala
    gn: Guinea
    gw: Guinea-bissau
    gy: Guyana
    ht: Haiti
    hm: Heard island and mcdonald islands
    va: Holy see (vatican city state)
    hn: Honduras
    hk: Hong kong
    hu: Hungary
    is: Iceland
    in: India
    id: Indonesia
    ir: Iran, islamic republic of
    iq: Iraq
    ie: Ireland
    il: Israel
    it: Italy
    jm: Jamaica
    jp: Japan
    jo: Jordan
    kz: Kazakhstan
    ke: Kenya
    ki: Kiribati
    kp: Korea, democratic people’s republic of
    kr: Korea, republic of
    kw: Kuwait
    kg: Kyrgyzstan
    la: Lao people’s democratic republic
    lv: Latvia
    lb: Lebanon
    ls: Lesotho
    lr: Liberia
    ly: Libyan arab jamahiriya
    li: Liechtenstein
    lt: Lithuania
    lu: Luxembourg
    mo: Macao
    mk: Macedonia, the former yugoslav republic of
    mg: Madagascar
    mw: Malawi
    my: Malaysia
    mv: Maldives
    ml: Mali
    mt: Malta
    mh: Marshall islands
    mq: Martinique
    mr: Mauritania
    mu: Mauritius
    yt: Mayotte
    mx: Mexico
    fm: Micronesia, federated states of
    md: Moldova, republic of
    mc: Monaco
    mn: Mongolia
    me: Montenegro
    ms: Montserrat
    ma: Morocco
    mz: Mozambique
    mm: Myanmar
    na: Namibia
    nr: Nauru
    np: Nepal
    nl: Netherlands
    an: Netherlands antilles
    nc: New caledonia
    nz: New zealand
    ni: Nicaragua
    ne: Niger
    ng: Nigeria
    nu: Niue
    nf: Norfolk island
    mp: Northern mariana islands
    no: Norway
    om: Oman
    pk: Pakistan
    pw: Palau
    ps: Palestinian territory, occupied
    pa: Panama
    pg: Papua new guinea
    py: Paraguay
    pe: Peru
    ph: Philippines
    pn: Pitcairn
    pl: Poland
    pt: Portugal
    pr: Puerto rico
    qa: Qatar
    re: Reunion
    ro: Romania
    ru: Russian federation
    rw: Rwanda
    sh: Saint helena
    kn: Saint kitts and nevis
    lc: Saint lucia
    pm: Saint pierre and miquelon
    vc: Saint vincent and the grenadines
    ws: Samoa
    sm: San marino
    st: Sao tome and principe
    sa: Saudi arabia
    sn: Senegal
    rs: Serbia
    sc: Seychelles
    sl: Sierra leone
    sg: Singapore
    sk: Slovakia
    si: Slovenia
    sb: Solomon islands
    so: Somalia
    za: South africa
    gs: South georgia and the south sandwich islands
    es: Spain
    lk: Sri lanka
    sd: Sudan
    sr: Suriname
    sj: Svalbard and jan mayen
    sz: Swaziland
    se: Sweden
    ch: Switzerland
    sy: Syrian arab republic
    tw: Taiwan, province of china
    tj: Tajikistan
    tz: Tanzania, united republic of
    th: Thailand
    tl: Timor-leste
    tg: Togo
    tk: Tokelau
    to: Tonga
    tt: Trinidad and tobago
    tn: Tunisia
    tr: Turkey
    tm: Turkmenistan
    tc: Turks and caicos islands
    tv: Tuvalu
    ug: Uganda
    ua: Ukraine
    ae: United arab emirates
    gb: United kingdom
    us: United states
    um: United states minor outlying islands
    uy: Uruguay
    uz: Uzbekistan
    vu: Vanuatu
    ve: Venezuela
    vn: Viet nam
    vg: Virgin islands, british
    vi: Virgin islands, u.s.
    wf: Wallis and futuna
    eh: Western sahara
    ye: Yemen
    zm: Zambia
    zw: Zimbabwe
    ax: Aland islands

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: