hexorx/countries — pull request #11 by esfourteen (2011-11-28 07:47:37+00:00)
Title: attribute based finder methods, override selected html option, fix for loading yaml.

I modified the Country class and overrode method_missing to add the following functionality:

find_by_attr(val)
find_country_by_attr(val)
find_all_by_attr(val)
find_all_countries_by_attr(val)

- find_by and find_all_by return the original hash or array of hash's from the Data hash
- find_country_by and find_all_countries_by returns a Country object or an array of Country objects

This mimics the original functionality you had for find_by_name and find_country_by_name.

A few examples:

Country.find_by_name('us') # returns Hash for country 'US'
Country.find_country_by_name('us') # returns Country object for 'US'
Country.find_by_alpha3('usa') # returns Hash for country 'US'
Country.find_all_countries_by_region('Americas') # returns array of Country objects where region => 'Americas'

I did not modify any tests yet as I couldn't get them to run, but I can fix that if you are interested in pulling in these changes.

Also in this commit is a fix for how yaml was being loaded, YAML is actually defined without including the yaml class, at least in 1.9.3, but with limited functionality, so the check for defined?(YAML) was insufficient.

And finally, I modified the country_select helper to allow overriding the selected html option.