Convert country name to country code

P

Petr Janda

Ive got the TZInfo library installed, and I am able to convert a country
code into country name, but I want to do it the other way around. Is it
possible?

Thanks,
Petr
 
R

rretzbach

Ive got the TZInfo library installed, and I am able to convert a country
code into country name, but I want to do it the other way around. Is it
possible?

Thanks,
Petr

I just took a small glimpse on the API doc and think it's not possible
with tzlib, cause they have a countries hash in the Form: {code =>
name}

add the following method to country.rb:

def self.get_code(identifier)
load_index
Indexes::Countries.countries.keys.find{|code| a
Code:
 ==
identifier}
end

Then you should be able to do Country.get_code("Germany").
Good luck :)
 
R

rretzbach

Indexes::Countries.countries.keys.find{|code| a
Code:
 ==
identifier}[/QUOTE]

Sry, too fast too furious!
a should be the same hash:

Indexes::Countries.countries.keys.find{|code|
Indexes::Countries.countries[code] == identifier}

Feel free to improve it :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,236
Messages
2,571,185
Members
47,820
Latest member
HortenseKo

Latest Threads

Top